From e9d9058b64d063cbf2c07b137ef6c01dcaafba2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20=28avd=29?= Date: Thu, 27 Jan 2022 14:47:53 +0000 Subject: [PATCH] [FIX] product: name_get performances Currently, product.name_get goes through each product in the record set before calling _get_combination_name on its attribute values. This can lead to some slowdowns when the recordset starts to grow (> 100 products). The reason for that is that _get_combination_name filters the recordset twice. This commit speed-up _get_combination_name by "resetting" prefetch_ids to self._prefetch_ids, i.e. the prefetch_ids of the whole recordset. opw-2624261 closes odoo/odoo#83563 X-original-commit: 2065c53a6e0c3f1c363f5b2bea401782a1f4b31b Signed-off-by: Raphael Collet --- addons/product/models/product_attribute.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_attribute.py b/addons/product/models/product_attribute.py index b8cbc42eebf..b4f01744140 100644 --- a/addons/product/models/product_attribute.py +++ b/addons/product/models/product_attribute.py @@ -554,7 +554,9 @@ class ProductTemplateAttributeValue(models.Model): def _get_combination_name(self): """Exclude values from single value lines or from no_variant attributes.""" - return ", ".join([ptav.name for ptav in self._without_no_variant_attributes()._filter_single_value_lines()]) + ptavs = self._without_no_variant_attributes().with_prefetch(self._prefetch_ids) + ptavs = ptavs._filter_single_value_lines().with_prefetch(self._prefetch_ids) + return ", ".join([ptav.name for ptav in ptavs]) def _filter_single_value_lines(self): """Return `self` with values from single value lines filtered out