From 716e5779164eaf2d353480dfd5498b200a8e85fe Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 16 Jan 2024 22:12:38 +1100 Subject: [PATCH] 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 --- .../management/commands/rebuild_thumbnails.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/InvenTree/InvenTree/management/commands/rebuild_thumbnails.py b/InvenTree/InvenTree/management/commands/rebuild_thumbnails.py index 8b54c98cc7..72512f6e44 100644 --- a/InvenTree/InvenTree/management/commands/rebuild_thumbnails.py +++ b/InvenTree/InvenTree/management/commands/rebuild_thumbnails.py @@ -4,6 +4,7 @@ """ import logging +import os from django.core.management.base import BaseCommand from django.db.utils import OperationalError, ProgrammingError @@ -26,6 +27,18 @@ class Command(BaseCommand): 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: