Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
uri-rodberg opened this issue Jan 31, 2023 · 5 comments
Open
Assignees

Comments

@uri-rodberg
Copy link
Contributor

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?

@acjh
Copy link

acjh commented Feb 19, 2023

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.

@uri-rodberg
Copy link
Contributor Author

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
Copy link
Contributor Author

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 uri-rodberg changed the title THUMBNAIL_CACHE_TIMEOUT usage Delete old thumbnails from media/cache directory and the database Feb 23, 2023
@uri-rodberg uri-rodberg changed the title Delete old thumbnails from media/cache directory and the database Delete old thumbnails from the media/cache directory and the database Feb 23, 2023
@uri-rodberg
Copy link
Contributor Author

uri-rodberg commented Feb 23, 2023

@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.

@claudep
Copy link
Contributor

claudep commented Feb 23, 2023

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

claudep added a commit to claudep/sorl-thumbnail that referenced this issue Sep 29, 2023
claudep added a commit to claudep/sorl-thumbnail that referenced this issue Sep 29, 2023
…erenced

Thanks Uri Rodberg for the report and the initial patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants