From 28d47d1977f0ddab53edb3bf9f85419ee1ec8d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Mon, 15 May 2023 11:25:37 +0000 Subject: [PATCH] [IMP] core: avoid extra invalidate of compute no-store field. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `tocompute` in the `Transaction` contains store field on records to be recomputed. No-store compute fields are directly invalidated from the cache when a dependency changes (see `BaseModel.modified`). In fact, `_recompute_field` was actually doing too much for nothing. Also, it may invalidate caches of compute no-store fields for no reason (e.g., if they are searchable). Remove the part for field compute no-store field. And prevent `_recompute_field` callers from calling it with no-store fields. closes odoo/odoo#122147 X-original-commit: ba9ccb07fb12558667db97b866df492fd0f5ba4d Signed-off-by: Raphael Collet Signed-off-by: Rémy Voet --- odoo/models.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index 8239fd03f80..9f983a177ec 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -6345,7 +6345,7 @@ class BaseModel(metaclass=MetaModel): fields = [self._fields[fname] for fname in fnames] for field in fields: - if field.compute: + if field.compute and field.store: self._recompute_field(field) def _recompute_recordset(self, fnames=None): @@ -6359,7 +6359,7 @@ class BaseModel(metaclass=MetaModel): fields = [self._fields[fname] for fname in fnames] for field in fields: - if field.compute: + if field.compute and field.store: self._recompute_field(field, self._ids) def _recompute_field(self, field, ids=None): @@ -6371,15 +6371,10 @@ class BaseModel(metaclass=MetaModel): if not ids: return - records = self.browse(ids) - if field.store: - # do not force recomputation on new records; those will be - # recomputed by accessing the field on the records - records = records.filtered('id') - field.recompute(records) - else: - self.env.cache.invalidate([(field, records._ids)]) - self.env.remove_to_compute(field, records) + # do not force recomputation on new records; those will be + # recomputed by accessing the field on the records + records = self.browse(tuple(id_ for id_ in ids if id_)) + field.recompute(records) # # Generic onchange method