From 3a1483635ed665b08af8cfe9adaec3f594e91a1b Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 16 Sep 2015 16:55:34 +0200 Subject: [PATCH] [IMP] fields: avoid `search` when recomputing a field on the same records This avoids a few dumb queries. --- openerp/fields.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/openerp/fields.py b/openerp/fields.py index 002445d6df1..d78cc3820a6 100644 --- a/openerp/fields.py +++ b/openerp/fields.py @@ -956,9 +956,12 @@ class Field(object): spec = [(self, records._ids)] for field, path in records._field_triggers[self]: if path and field.store: - # don't move this line to function top, see log - env = records.env(user=SUPERUSER_ID, context={'active_test': False}) - target = env[field.model_name].search([(path, 'in', records.ids)]) + if path == 'id': + target = records + else: + # don't move this line to function top, see log + env = records.env(user=SUPERUSER_ID, context={'active_test': False}) + target = env[field.model_name].search([(path, 'in', records.ids)]) if target: spec.append((field, target._ids)) # recompute field on target in the environment of records,