[FIX] api: in todo list, group records to recompute by environment (#11267)

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:
Richard Möhn 2016-10-13 17:13:33 +09:00 committed by Raphael Collet
parent d3609f7f19
commit cb581bc14f
1 changed files with 8 additions and 2 deletions

View File

@ -892,7 +892,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,
@ -905,7 +906,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``. """