[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 <amoyaux@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user