From 4f582eee869ce667f18733063cb4a589653ca65b Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Tue, 21 Nov 2023 10:57:41 +0100 Subject: [PATCH] [PERF] website_sale: do not load all the product tags Checking on the searched products whether they have tags (through the field) before searching for them is highly inefficient, will fill the orm records cache for "nothing", and will be executed in slow, separate queries, highly slowing down the /shop page loading time. Part-of: odoo/odoo#142860 --- addons/website_sale/controllers/main.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 444c42e3402..472e986106e 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -398,18 +398,15 @@ class WebsiteSale(payment_portal.PaymentPortal): max_price = max_price if max_price >= available_min_price else available_max_price post['max_price'] = max_price - if filter_by_tags_enabled: - if ( - search_product.product_tag_ids - or search_product.product_variant_ids.additional_product_tag_ids - ): - ProductTag = request.env['product.tag'] - all_tags = ProductTag.search( - [('product_ids.is_published', '=', True), ('visible_on_ecommerce', '=', True)] - + website_domain - ) - else: - all_tags = [] + if filter_by_tags_enabled and search_product: + ProductTag = request.env['product.tag'] + all_tags = ProductTag.search( + expression.AND([ + [('product_ids.is_published', '=', True), ('visible_on_ecommerce', '=', True)], + website_domain + ]) + ) + categs_domain = [('parent_id', '=', False)] + website_domain if search: search_categories = Category.search(