Skip to content

Commit

Permalink
Update rebuild_thumbnails command (#6254)
Browse files Browse the repository at this point in the history
* Update rebuild_thumbnails command

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

* Refactoring
  • Loading branch information
SchrodingersGat committed Jan 16, 2024
1 parent 8eec2f3 commit 716e577
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions InvenTree/InvenTree/management/commands/rebuild_thumbnails.py
Expand Up @@ -4,6 +4,7 @@
"""

import logging
import os

from django.core.management.base import BaseCommand
from django.db.utils import OperationalError, ProgrammingError
Expand All @@ -26,6 +27,18 @@ def rebuild_thumbnail(self, model):

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)

try:
Expand Down

0 comments on commit 716e577

Please sign in to comment.