summaryrefslogtreecommitdiff
path: root/addons/base_import/models
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2017-08-14 10:15:53 +0200
committerYannick Tivisse <yti@odoo.com>2017-08-14 15:02:52 +0200
commitfd089ee467bd3270e1c7d842f98817e43e20df9f (patch)
tree9079148181133aaf080e6084f8875871257347d3 /addons/base_import/models
parenta2361e23ea95c308ac7576c614c0a1938707def0 (diff)
[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.
Diffstat (limited to 'addons/base_import/models')
-rw-r--r--addons/base_import/models/base_import.py8
1 files changed, 7 insertions, 1 deletions
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