From 5db82daa8dfa8ddd25c45e4b951a3876a5510288 Mon Sep 17 00:00:00 2001 From: Zachary Hanham Date: Fri, 15 Mar 2024 13:48:11 -0400 Subject: [PATCH] [FIX] pos_self_order: use stored fields to check if product "has_image" For method `_get_product_for_ui` in pos_self_order's product.product extension, check fields `product_tmpl_id.image_128` and/or `image_variant_128` for the existance of an image on the product (`has_image` key). Previously, the field `image_1920` was used which has two issues: 1.) The 128 sized image should be preferred because it is 15x smaller than 1920. The whole image is loaded at this point, so the smallest-sized one should be used. 2.) `image_1920` is a computed, non-stored, field. This has the implication that the image will be processed, thus consuming more memory (even leading to a MemoryError on the customer's DB). This happens like so: a.) `_compute_image_1920` is called, which sets a value into `record.image_1920`. https://github.com/odoo/odoo/blob/38f37edad3da4a4547b73d971e053b0634067fa1/addons/product/models/product_product.py#L157 b.) Eventually `_image_process` is called, which performs memory intensive computations on the image. https://github.com/odoo/odoo/blob/38f37edad3da4a4547b73d971e053b0634067fa1/odoo/fields.py#L2550 So this can be avoided by implementing this commit, which will check the stored, non-computed fields instead. Memory benchmarks for allocations by `_get_self_order_data`: Done on customer DB with 1340 product.products, with a total of 776 images between them. Before commit: 1638.4 MiB + server memory limit reached After commit: 29.7 MiB total Total improvement of 55x less memory usage closes odoo/odoo#157900 Signed-off-by: Vlad Stroia (vlst) --- addons/pos_self_order/models/product_product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/pos_self_order/models/product_product.py b/addons/pos_self_order/models/product_product.py index 3f227392a8c..413f7a059b5 100644 --- a/addons/pos_self_order/models/product_product.py +++ b/addons/pos_self_order/models/product_product.py @@ -186,7 +186,7 @@ class ProductProduct(models.Model): self.ensure_one() return { "price_info": self._get_price_info(pos_config), - "has_image": bool(self.image_1920), + "has_image": bool(self.product_tmpl_id.image_128 or self.image_variant_128), "attributes": self._get_attributes(pos_config), "name": self._get_name(), "id": self.id,