News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

Cleanup old thumbnails

Started by Skinny, June 09, 2015, 08:58:26 AM

Previous topic - Next topic

Skinny

Good morning,

Is there a way to delete all generated attachment thumbnails safely and let SMF regenerate them when needed (when a visitors visits a topic) ?
I have a lots and lots of thumbnails taking up diskspace from threads that are not visited anymore (2008-2012) and would like to delete those thumbnails until they are needed again.

Thanks,
Mark

Kindred

I could be wrong, but I do not believe so...

AFAIK, SMF does not generate thumbnails on the fly...  it generates them when created and that's it.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Skinny

I'm sort of familar with the sources of SMF and when I look at Display.php i see :

                     // Let's see, do we want thumbs?
                        if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSe$
                        {
                                // A proper thumb doesn't exist yet? Create one!
                                if (empty($attachment['id_thumb']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeigh$
                                {
                                        $filename = getAttachmentFilename($attachment['filename'], $attachment['id_attach'], $attachment['id_folder']);

                                        require_once($sourcedir . '/Subs-Graphics.php');
                                        if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight']))
                                        {




This would suggest that the code generates the thumbnail (Again) when it's not available, but I just need to be sure if it's safe to just select thumbs from the attachments table and delete those records and corresponding files from the filesystem.

Mark

margarett

Yes, indeed SMF generates the attachments thumbnails on the fly if they don't exist.

Look at the attachments table, it should be easy to see which are thumbs (a better reply will arrive when I'm at the computer)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

ah...   it seems that I was incorrect. :P

Margarett will be able to assist better... :)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

Well, there is a easy part and a not-so-easy part :P

It is *very* easy if you have not so many thumbs... If this is the case, you can go to your admin
index.php?action=admin;area=manageattachments;sa=browse;thumbs
And just select all thumbs, remove, repeat until done.

But as you said that they are occupying a lot of space, I guess this won't be the case :(

It is easy to identify thumbs: check smf_attachments table, get everything with attachment_type = 3. Then just build the file name on disc (id + "_" + file_hash), @unlink it and remove the database row. Easy enough. Unfortunately you need to do this in some kind of loop with just some operations every time (and a pause) or you will probably stall MySQL if you throw him some thousand operations in few seconds...

Let me know if you need help building the code ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Skinny

Thanks for the great reply! With this info and a little bit of Excel magic I was able to create two scripts:

1) Delete all the attachments from the filesystem (ID_GUID)
2) Delete the relevant records from the database and update the id_thumb column of the parent record to 0

Reclaimed around 50GB of old thumbs !

Mark

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: