From 195c2fc05f2a2ff4f80bd49066803974519d5a9b Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli <nim@odoo.com> Date: Thu, 31 May 2018 15:30:40 +0200 Subject: [PATCH] [FIX] website_sale: performance with carousel When the carousel is activated, the following will load all variant ids in the cache (cf. `_in_cache_without`): ``` <t t-set="variant_img" t-value="any(product.mapped('product_variant_ids.image_variant'))"/> ``` When accessing the `image` field at: ``` <div t-if="variant_img" class="..." itemprop="image" t-field="product.product_variant_id.image" t-options="..."/> ``` All variants in cache will have their image resized by the method `_compute_images` on `product.product`. In case of a product with hundreds of variants with images, this will take a major amount of time. If we replace by `product[:1]`, the system uses another cache, and doesn't fetch the image of all variants. opw-1844783 --- addons/website_sale/views/templates.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index a63ade4e5963..2deaaf833b5a 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -417,7 +417,7 @@ <div id="o-carousel-product" class="carousel slide" data-ride="carousel" data-interval="0"> <div class="carousel-outer"> <div class="carousel-inner"> - <div t-if="variant_img" class="item active" itemprop="image" t-field="product.product_variant_id.image" t-options="{'widget': 'image', 'class': 'product_detail_img js_variant_img', 'alt-field': 'name', 'zoom': 'image', 'unique': product['__last_update'] + (product.product_variant_id['__last_update'] or '')}"/> + <div t-if="variant_img" class="item active" itemprop="image" t-field="product[:1].product_variant_id.image" t-options="{'widget': 'image', 'class': 'product_detail_img js_variant_img', 'alt-field': 'name', 'zoom': 'image', 'unique': product['__last_update'] + (product.product_variant_id['__last_update'] or '')}"/> <div t-attf-class="item#{'' if variant_img else ' active'}" itemprop="image" t-field="product.image" t-options="{'widget': 'image', 'class': 'product_detail_img', 'alt-field': 'name', 'zoom': 'image', 'unique': product['__last_update']}"/> <t t-if="len(image_ids)" t-foreach="image_ids" t-as="pimg"> <div class="item" t-field="pimg.image" t-options='{"widget": "image", "class": "product_detail_img", "alt-field": "name", "zoom": "image" }'/> -- GitLab