From e6cbfe64762786455c28fcb95446244da2b8ed7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Mon, 23 Nov 2020 12:17:12 +0000 Subject: [PATCH] [FIX] stock: avoid flush all env in quants update Issue: The `_update_available_quantity` will flush the all environment due to the savepoint (at each call). When we working with the package, it becomes bottleneck due to the `_compute_package_info`. Indeed, it computes two compute store field (`location_id` and `company_id`) and depends of multiple field of related quants `quants_ids.xxx`. It means that each time we enter/exit in the savepoint to update quants, this compute will be execute (because of flush + compute_store). Solution: Avoid flushing when enter in the savepoint of `_update_available_quantity` (`flush=False`) Performance gain: To validate a Delivery with 1000 move lines with package (source and dest): - Without patch: +- 120 sec - With patch: +- 17 sec opw-2371161 closes odoo/odoo#62841 X-original-commit: b2d57323caf9f7fe47c4fe9ac26b0e955d9987b9 Signed-off-by: Arnold Moyaux Signed-off-by: William Henrotin --- addons/stock/models/stock_quant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 15c5b4c7a4e..b4fe09f8066 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -414,7 +414,7 @@ class StockQuant(models.Model): for quant in quants: try: - with self._cr.savepoint(): + with self._cr.savepoint(flush=False): # Avoid flush compute store of package self._cr.execute("SELECT 1 FROM stock_quant WHERE id = %s FOR UPDATE NOWAIT", [quant.id], log_exceptions=False) quant.write({ 'quantity': quant.quantity + quantity,