sorl-thumbnail icon indicating copy to clipboard operation
sorl-thumbnail copied to clipboard

Delete old thumbnails from the media/cache directory and the database

Open uri-rodberg opened this issue 2 years ago • 5 comments

Hi,

We use sorl-thumbnail in our project (Speedy Net) and I defined THUMBNAIL_CACHE_TIMEOUT = int(60 * 60 * 24 * 90) # 90 days. I want every thumbnail to be regenerated if it's more than 90 days old. But I'm not sure if our thumbnails are regenerated after 90 days, do you know how I can check it? Because our media/cache/ directory contains many files more than 90 days old. How do I check if all the thumbnails displayed on our website are less than 90 days old?

uri-rodberg avatar Jan 31 '23 18:01 uri-rodberg

THUMBNAIL_CACHE_TIMEOUT only applies to the cache, not the kvstore (database) nor the storage (filesystem). It means that the file path stored in cache will be expired, and the application will need to query the kvstore (database) for the information.

I added a management command to delete the cache, kvstore (database) and storage (filesystem) if the file's created time is before THUMBNAIL_CACHE_TIMEOUT seconds ago in #724. You can use a daily or hourly cron job to call it.

acjh avatar Feb 19 '23 16:02 acjh

I added a management command to delete the cache, kvstore (database) and storage (filesystem) if the file's created time is before THUMBNAIL_CACHE_TIMEOUT seconds ago in #724. You can use a daily or hourly cron job to call it.

Hi Aaron, I think THUMBNAIL_CACHE_TIMEOUT only applies to the cache, as you said, so I don't think it's appropriate to use it in the new management command you added. Maybe add this as a command line argument, or another setting? @claudep What do you think? Since this is given in seconds, maybe another setting? And if this setting is not defined, maybe this command will not do anything? Or do you want to define a default?

uri-rodberg avatar Feb 19 '23 17:02 uri-rodberg

Hi Aaron. @claudep is not responding, so let's make a decision. I think you can define a new setting for the new action you added, which will be the number of seconds ago to remove files from the cache file system and the database. The default will be 90 days (int(60 * 60 * 24 * 90) # 90 days), and in Speedy Net I think I will define it as 92 days (int(60 * 60 * 24 * 92) # 92 days). So if the admin will not define this setting, it will be 90 days. Please change your PR to use the new setting, instead of using THUMBNAIL_CACHE_TIMEOUT.

uri-rodberg avatar Feb 23 '23 15:02 uri-rodberg

@acjh Also, please update https://github.com/jazzband/sorl-thumbnail/blob/master/docs/management.rst with the documentation for the new command in your PR. Is this taken as it is to https://sorl-thumbnail.readthedocs.io/en/latest/management.html? And also, if relevant please create tests to test that your new command is working properly.

And the new setting, please document at https://github.com/jazzband/sorl-thumbnail/blob/master/docs/reference/settings.rst.

uri-rodberg avatar Feb 23 '23 15:02 uri-rodberg

I'm sorry, I'm a bit overwhelmed right now.

claudep avatar Feb 23 '23 19:02 claudep