From b65377e89e5148a64d114642a256cc0d23dcf7e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 21 Jan 2025 18:35:56 +0100 Subject: [PATCH] Read only the image from the selected cache Using the instance from the list of cache, the ORM read the image for all the linked cache which is unnecessary. Closes #13831 --- modules/product_image/product.py | 3 ++- trytond/trytond/ir/avatar.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/product_image/product.py b/modules/product_image/product.py index 9979decd76..37c5f5df8a 100644 --- a/modules/product_image/product.py +++ b/modules/product_image/product.py @@ -158,7 +158,8 @@ class ImageMixin(_ImageMixin): raise ValueError(f"Invalid size {size}") for cache in self.cache: if (cache.width, cache.height) == size: - return cache.image + # re-instantiate to fetch only one image + return cache.__class__(cache.id).image with Transaction().new_transaction(): cache = self._store_cache(size, self._resize(size)) # Save cache only if record is already committed diff --git a/trytond/trytond/ir/avatar.py b/trytond/trytond/ir/avatar.py index 6c820f6464..6aa5aa9af5 100644 --- a/trytond/trytond/ir/avatar.py +++ b/trytond/trytond/ir/avatar.py @@ -99,7 +99,8 @@ class Avatar(ImageMixin, ResourceMixin, ModelSQL): raise ValueError("Invalid size") for avatar in self.cache: if avatar.size == size: - return avatar.image + # re-instantiate to fetch only one image + return avatar.__class__(avatar.id).image if not self.image: return None if PIL: