[IMP] mrp: add index on bom_id for byproduct

The `bom_id` field has a One2many inverse `byproduct_ids`
then it should by index to avoid bottleneck if byproduct is
highly used by a lot of different BoM

Performance improvements:
When there is 20K of Byproduct line, read a BoM is x1.8 faster.

task-2389380
This commit is contained in:
Rémy Voet (ryv)
2020-12-22 12:43:00 +00:00
parent aa898c9a33
commit d346cd1ec2
+1 -1
View File
@@ -432,7 +432,7 @@ class MrpByProduct(models.Model):
'Quantity',
default=1.0, digits='Product Unit of Measure', required=True)
product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True)
bom_id = fields.Many2one('mrp.bom', 'BoM', ondelete='cascade')
bom_id = fields.Many2one('mrp.bom', 'BoM', ondelete='cascade', index=True)
allowed_operation_ids = fields.Many2many('mrp.routing.workcenter', compute='_compute_allowed_operation_ids')
operation_id = fields.Many2one(
'mrp.routing.workcenter', 'Produced in Operation', check_company=True,