From fd089ee467bd3270e1c7d842f98817e43e20df9f Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Mon, 14 Aug 2017 10:15:53 +0200 Subject: [PATCH] [IMP] base_import: Defer parent computation after record creation/update Currently when importing files, the parent left and right are recomputed on each record creation/update, which could lead to a lot a request. This commit will defer the parent field recomputation to the end on the `load` function by recomputing the values from the MPTT and inserting directly the new values on the records. Tested on a customer instance, this will reduce the execution time when importing a thousand stock.location from 15 minutes to several seconds. --- addons/base_import/models/base_import.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/base_import/models/base_import.py b/addons/base_import/models/base_import.py index b9e22ad9925..e970d1ca3ad 100644 --- a/addons/base_import/models/base_import.py +++ b/addons/base_import/models/base_import.py @@ -664,7 +664,13 @@ class Import(models.TransientModel): }] _logger.info('importing %d rows...', len(data)) - import_result = self.env[self.res_model].with_context(import_file=True).load(import_fields, data) + + model = self.env[self.res_model].with_context(import_file=True) + defer_parent_store = self.env.context.get('defer_parent_store_computation', True) + if defer_parent_store and model._parent_store: + model = model.with_context(defer_parent_store_computation=True) + + import_result = model.load(import_fields, data) _logger.info('done') # If transaction aborted, RELEASE SAVEPOINT is going to raise