[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.
This commit is contained in:
Yannick Tivisse
2017-08-14 15:02:52 +02:00
parent a2361e23ea
commit fd089ee467
+7 -1
View File
@@ -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