[FIX] openerp models.py: Add recompute conditional in unlink

Description of the issue/feature this PR addresses:

This commit adds the recompute conditional clause in the ORM unlink method.
This behaviour is already present in branch 10.0 as it can be seen in line 3431.
With this, the possibility of disabling the automatic recalculation of computed fields is given back to the developer of custom modules in performance critical scenarios. By using the Environment class "norecompute" context manager, the developer can now unlink records in a very fast manner and afterwards, execute the computed fields manually if needed (via an explicit method call or a direct sql update).

Current behavior before PR:

Having this option in the ORM will allow to speed up the system if needed when massive collateral changes must be made. One of this scenarios has to do with the modification of one2many fields and the write_uid and write_date computed fields. In the account module for example, when unreconciling account move lines,  the deletion of the partial reconcile records involved in the reconciliation triggers a one by one update of the related account move lines and account moves. If the involved documents are big, such an account move (Journal Entry) with thousands of lines, if one of its lines is reconciled and afterwards unreconciled, the process can take several minutes due to expensive one by one recomputations such as the ones involved in the modification of the write_uid and the write_date in the models.py recompute() method. This modifications can however be enforced later with a couple of SQL update statements, instead of thousands of them executed by a for loop.

Desired behavior after PR is merged:

Developers of custom modules will now have the possibility of disabling the automatic calculation of computed fields, as it can be done in the create method (models.py "_create()" line 4370). This is vital for performance reasons, specially when handling big documents such as thousands of lines account moves or sales orders.

This is basically a backport of revision f259e74f8a
This commit is contained in:
Esteban Echeverry
2017-01-30 13:51:32 +01:00
committed by Denis Ledoux
parent 9c9003d257
commit b14ef6346d
+4 -1
View File
@@ -3652,6 +3652,8 @@ class BaseModel(object):
return True
if isinstance(ids, (int, long)):
ids = [ids]
if not context:
context = {}
result_store = self._store_get_values(cr, uid, ids, self._fields.keys(), context)
@@ -3727,7 +3729,8 @@ class BaseModel(object):
obj._store_set_values(cr, uid, rids, fields, context)
# recompute new-style fields
recs.recompute()
if recs.env.recompute and context.get('recompute', True):
recs.recompute()
# auditing: deletions are infrequent and leave no trace in the database
_unlink.info('User #%s deleted %s records with IDs: %r', uid, self._name, ids)