[IMP] api: in todo list, group records to recompute by environment

The effect of this change is to trigger the recomputation of fields on larger
recordsets.  This takes advantage of batch computations within compute methods.
This commit is contained in:
Raphael Collet
2015-09-16 11:56:44 +02:00
parent 9d36fe5c52
commit 5805b87005
+8 -2
View File
@@ -832,7 +832,8 @@ class Environment(object):
with all records to recompute for ``field``.
"""
if field in self.all.todo:
return reduce(operator.or_, self.all.todo[field])
ids = set(rid for recs in self.all.todo[field] for rid in recs.ids)
return self[field.model_name].browse(ids)
def check_todo(self, field, record):
""" Check whether ``field`` must be recomputed on ``record``, and if so,
@@ -845,7 +846,12 @@ class Environment(object):
def add_todo(self, field, records):
""" Mark ``field`` to be recomputed on ``records``. """
recs_list = self.all.todo.setdefault(field, [])
recs_list.append(records)
for i, recs in enumerate(recs_list):
if recs.env == records.env:
recs_list[i] |= records
break
else:
recs_list.append(records)
def remove_todo(self, field, records):
""" Mark ``field`` as recomputed on ``records``. """