Update rebuild_thumbnails command (#6254)

* Update rebuild_thumbnails command

- Skip if images already exist
- Prevents significant clutter in the logs
- Speeds up the command too

* Refactoring
This commit is contained in:
Oliver 2024-01-16 22:12:38 +11:00 committed by GitHub
parent 8eec2f32c0
commit 716e577916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
""" """
import logging import logging
import os
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db.utils import OperationalError, ProgrammingError from django.db.utils import OperationalError, ProgrammingError
@ -26,6 +27,18 @@ class Command(BaseCommand):
img = model.image img = model.image
# Check for image paths
img_paths = []
for x in [model.image, model.image.thumbnail, model.image.preview]:
if x and x.path:
img_paths.append(x.path)
if len(img_paths) > 0:
if all((os.path.exists(path) for path in img_paths)):
# All images exist - skip further work
return
logger.info("Generating thumbnail image for '%s'", img) logger.info("Generating thumbnail image for '%s'", img)
try: try: