From c8b3035efc955c1443af95439bfa46cc98245bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Thu, 31 Dec 2020 09:20:07 +0000 Subject: [PATCH] [FIX] mrp: add indexes on highly search fields Add two indexes (on `product_id` and `product_tmpl_id`) on the `mrp.bom` model to speed up `_bom_find` which is highly used and it uses always the `product_tmpl_id` and sometime the `product_id` in the search domain. Performance Gain: With a DB with 2K BoM, a `_bom_find` search (`product_id` and `product_tmpl_id` are in domain): The SQL execution time is +- 5 times faster. task-2390516 closes odoo/odoo#64934 X-original-commit: 64861aed03b616820d717bc08e7c38c56145e0f2 Signed-off-by: Arnold Moyaux --- addons/mrp/models/mrp_bom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index 00b6d961943..b4789826062 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -31,11 +31,11 @@ class MrpBom(models.Model): default='normal', required=True) product_tmpl_id = fields.Many2one( 'product.template', 'Product', - check_company=True, + check_company=True, index=True, domain="[('type', 'in', ['product', 'consu']), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", required=True) product_id = fields.Many2one( 'product.product', 'Product Variant', - check_company=True, + check_company=True, index=True, domain="['&', ('product_tmpl_id', '=', product_tmpl_id), ('type', 'in', ['product', 'consu']), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", help="If a product variant is defined the BOM is available only for this product.") bom_line_ids = fields.One2many('mrp.bom.line', 'bom_id', 'BoM Lines', copy=True)