From 0a7268f6ef8bc2f2b42170aa6305f46ee112daf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 13 Feb 2021 11:15:16 +0100 Subject: [PATCH] Do not instantiate other fields loaded eagerly It has a cost to instantiate such fields and there is not guarantee that they will be used. But as their values are stored in the cache, if they are needed they can be instantiated using only the cache values. Also there is no real benefit in instantiate two fields together. issue10026 review341251002 --- trytond/model/modelstorage.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 747089cde6..3da3a3f35c 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -1624,6 +1624,7 @@ class ModelStorage(Model): read_data = self.read(list(index.keys()), list(ffields.keys())) read_data.sort(key=lambda r: index[r['id']]) # create browse records for 'remote' models + no_local_cache = {'one2one', 'one2many', 'many2many', 'binary'} for data in read_data: id_ = data['id'] to_delete = set() @@ -1632,12 +1633,16 @@ class ModelStorage(Model): if field._type in { 'many2one', 'one2one', 'one2many', 'many2many', 'reference'}: + if (fname != name + and not require_context_field + and field._type not in no_local_cache): + continue fvalue = instantiate(field, data[fname], data) if id_ == self.id and fname == name: value = fvalue - self._local_cache[id_][fname] = fvalue - if (field._type in { - 'one2one', 'one2many', 'many2many', 'binary'} + if fname not in self._local_cache[id_]: + self._local_cache[id_][fname] = fvalue + if (field._type in no_local_cache or field.context or getattr(field, 'datetime_field', None) or isinstance(field, fields.Function)):