From e55aa95f2a55a0e01fd6f1adc7a988c542efa3de Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 28 Aug 2017 16:36:20 +0200 Subject: [PATCH] [FIX] website_sale: very slow shop grid and product view The problem is present because there are more than 1000 variants for each product. For display, the price of each product is recalculated (instead of looking only at the last product) opw-766897 --- addons/website_sale/models/product.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index d3e1c6b893a..1b017ff67d1 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -141,11 +141,13 @@ class ProductTemplate(models.Model): website_public_price = fields.Float('Website public price', compute='_website_price', digits=dp.get_precision('Product Price')) def _website_price(self): - self.mapped('product_variant_id') - - for p in self: - p.website_price = p.product_variant_id.website_price - p.website_public_price = p.product_variant_id.website_public_price + # First filter out the ones that have no variant: + # This makes sure that every template below has a corresponding product in the zipped result. + self = self.filtered('product_variant_id') + # use mapped who returns a recordset with only itself to prefetch (and don't prefetch every product_variant_ids) + for template, product in zip(self, self.mapped('product_variant_id')): + template.website_price = product.website_price + template.website_public_price = product.website_public_price def _default_website_sequence(self): self._cr.execute("SELECT MIN(website_sequence) FROM %s" % self._table)