From fa1f0502180338cb2fd614c1efae7548d8e0c959 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 28 Jun 2018 10:18:06 +0200 Subject: [PATCH] [FIX] sale_stock: performance In some undertermined circumstances, a `KeyError` might appear in: https://github.com/odoo/odoo/blob/f9737d79e77e9abf634c8eaa4b6ea331e2aa814d/odoo/models.py#L4898-L4904 Despite the lack of reproducible use case, it seems that this was introduced from 59b010ac366e0826fb314. In the meantime, other optimizations were introduced in the prefetching of related fields, and it seems that the fix is not necessary anymore. Running the same script than described in https://github.com/odoo/odoo/issues/19536#issuecomment-333118947 , we observe the following performances: Before the fix: ``` On change with 10 lines (10 new, 0 existing) took 0.306 On change with 20 lines (10 new, 10 existing) took 0.221 On change with 30 lines (10 new, 20 existing) took 0.208 On change with 40 lines (10 new, 30 existing) took 0.271 On change with 50 lines (10 new, 40 existing) took 0.306 On change with 60 lines (10 new, 50 existing) took 0.319 On change with 70 lines (10 new, 60 existing) took 0.354 On change with 80 lines (10 new, 70 existing) took 0.382 On change with 90 lines (10 new, 80 existing) took 0.506 On change with 100 lines (10 new, 90 existing) took 0.503 ``` After the fix: ``` On change with 10 lines (10 new, 0 existing) took 0.238 On change with 20 lines (10 new, 10 existing) took 0.259 On change with 30 lines (10 new, 20 existing) took 0.250 On change with 40 lines (10 new, 30 existing) took 0.233 On change with 50 lines (10 new, 40 existing) took 0.287 On change with 60 lines (10 new, 50 existing) took 0.325 On change with 70 lines (10 new, 60 existing) took 0.345 On change with 80 lines (10 new, 70 existing) took 0.451 On change with 90 lines (10 new, 80 existing) took 0.496 On change with 100 lines (10 new, 90 existing) took 0.423 ``` The fix doesn't seem to be necessary anymore, so we go back to the previous implementation of the computed field. Closes #25448 Fixes #19536 opw-1861468 --- addons/sale_stock/models/sale_order.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 06f1ef715ba..64d4398cba1 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -109,13 +109,9 @@ class SaleOrderLine(models.Model): @api.multi @api.depends('product_id') def _compute_qty_delivered_updateable(self): - # prefetch field before filtering - self.mapped('product_id') - # on consumable or stockable products, qty_delivered_updateable defaults - # to False; on other lines use the original computation - lines = self.filtered(lambda line: line.product_id.type not in ('consu', 'product')) - lines = lines.with_prefetch(self._prefetch) - super(SaleOrderLine, lines)._compute_qty_delivered_updateable() + for line in self: + if line.product_id.type not in ('consu', 'product'): + super(SaleOrderLine, line)._compute_qty_delivered_updateable() @api.onchange('product_id') def _onchange_product_id_set_customer_lead(self):