[IMP] models: use raw sql for modified()
Avoiding search makes modified go from 18% of total runtime to 9% over 10k calls (though only 5k search() call).
This commit is contained in:
+10
-3
@@ -5108,9 +5108,16 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
|||||||
if path == 'id':
|
if path == 'id':
|
||||||
target0 = self
|
target0 = self
|
||||||
else:
|
else:
|
||||||
env = self.env(user=SUPERUSER_ID, context={'active_test': False})
|
Model = self.env[model_name]
|
||||||
target0 = env[model_name].search([(path, 'in', self.ids)])
|
f = Model._fields.get(path)
|
||||||
target0 = target0.with_env(self.env)
|
if f and f.store and f.type not in ('one2many', 'many2many'):
|
||||||
|
# path is direct (not dotted), stored, and inline -> optimise to raw sql
|
||||||
|
self.env.cr.execute("SELECT id FROM %s WHERE %s in %%s" % (Model._table, path), [tuple(self.ids)])
|
||||||
|
target0 = Model.browse(i for [i] in self.env.cr.fetchall())
|
||||||
|
else:
|
||||||
|
env = self.env(user=SUPERUSER_ID, context={'active_test': False})
|
||||||
|
target0 = env[model_name].search([(path, 'in', self.ids)])
|
||||||
|
target0 = target0.with_env(self.env)
|
||||||
# prepare recomputation for each field on linked records
|
# prepare recomputation for each field on linked records
|
||||||
for field in stored:
|
for field in stored:
|
||||||
# discard records to not recompute for field
|
# discard records to not recompute for field
|
||||||
|
|||||||
Reference in New Issue
Block a user