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
This commit is contained in:
Cédric Krier
2021-02-13 11:15:16 +01:00
parent ff2cc6dd21
commit 0a7268f6ef
+8 -3
View File
@@ -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)):