From 9253643fd04b850b4eb405a39693f186d8b31d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 29 Jan 2021 15:25:52 +0000 Subject: [PATCH] [FIX] product: fix performance tree/kanban views product The compute of `product_variant_count` was highly inefficient in batch. It is due to `with_prefetch` which remove the prefetch (reset _prefetch_ids = _ids) of the for loop. It was added by 05a00fa9d4f001cef6d31a5b8d20a847de4f455b which fixed performance issue for the 11.0 about `sales_count`. But with the new ORM (13.0) compute fields are lazy. Performance improvements: For the search_read of the kanban view (Menu: Sale/Products/Products) with the default pagination (80 items): Before: 347 SQL request and 0.31 +- 0.2 sec (Python and SQL time) After: 110 SQL request and 0.14 +- 0.2 sec (Python and SQL time) task-2439019 --- addons/product/models/product_template.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 29fce0b17f8..aec908eede4 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -345,8 +345,7 @@ class ProductTemplate(models.Model): @api.depends('product_variant_ids.product_tmpl_id') def _compute_product_variant_count(self): for template in self: - # do not pollute variants to be prefetched when counting variants - template.product_variant_count = len(template.with_prefetch().product_variant_ids) + template.product_variant_count = len(template.product_variant_ids) @api.depends('product_variant_ids', 'product_variant_ids.default_code') def _compute_default_code(self):