From 5805b87005f000900353c8b2f98f9cf037cb3050 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 15 Sep 2015 09:13:02 +0200 Subject: [PATCH] [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. --- openerp/api.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openerp/api.py b/openerp/api.py index 6a330c0020f..51becd31b7f 100644 --- a/openerp/api.py +++ b/openerp/api.py @@ -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``. """