News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Attachments bug (v2.1.4)

Started by szinski, July 01, 2024, 08:56:26 AM

Previous topic - Next topic

szinski

Just migrated a large forum to v2.1.4

Forum has almost 300,000 attachments (images).

On old forum, all attachments were in one folder (attachments). I configured the new forum for auto management of the attachment directories and set a limit of 1,000 images per directory. Ran File Maintenance to process and move the files, everything ran fine until it reached "attachments_127" at which time it threw an error about "id_folder" exceeding max value in the database. id_folder in smf_attachments was set to type "tinyint" which can only store a max value of 127. Doh!

So, I changed the column type to "int" and re-ran file maintenance and no more issues.

This needs to be fixed so that forums with a large number of images don't run into issues.

szinski

Seeing another issue where forum is not filling up the directories before creating a new directory (see attached image).

Settings are:

(Auto) when either directory space limit is reached
Create new directories within base directory (checked)
Maximum number of files per directory (1000)
Max attachment directory space (0)

szinski

I have determined that the "(Auto) when either directory space limit is reached" setting is broken

I set up a new test forum from scratch, and when using that setting it creates a new attachments_xxx folder each time someone posts an image. I made three different posts (with an image) and I ended up with:

attachments_0 (2 files)
attachments_1 (2 files)
attachments_2 (2 files)

I adjusted the number of files per directory, and the max attachment space, and it made no difference.

I was able to get things fixed by using "(Auto) Subdivide by years and months" which is now using one folder (attachments/2024/07) for all new images.

Can someone tell me where I can find the "attachments_" folder values stored in the database? On one of my forums, I have 300+ empty attachment folders and I can't remove them because I get a malformed JSON request when I blank them out and submit (I think the string is too long). I'd like to manually delete those folders from the database to get things cleaned up.

szinski

Follow up to my previous message. Found the setting in the attachments table under attachmentUploadDir (stored as a JSON object). I'll hand-edit that JSON and remove all the empty folders, then delete the empty folders from disk. That should do the trick, right?

shawnb61

Quote from: szinski on July 02, 2024, 12:44:45 PMFollow up to my previous message. Found the setting in the attachments table under attachmentUploadDir (stored as a JSON object). I'll hand-edit that JSON and remove all the empty folders, then delete the empty folders from disk. That should do the trick, right?

Only if done carefully... 

Note that the folder #, stored on the attachment record, is used to find the attachment folder, and refers to the actual array entry in the JSON array.  Hand-editing that JSON can break the connection between the attachment folder and the attachment.

I.e., removing one folder entry in the middle effectively renumbers all the subsequent ones, which may make it impossible for SMF to find those attachments.

I believe it is safe to remove items at the end that refer to empty folders.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: