changeset 42deab7e7838 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=42deab7e7838
description:
        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
diffstat:

 trytond/model/modelstorage.py |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (31 lines):

diff -r bdea3f9af35f -r 42deab7e7838 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py     Fri Feb 12 10:01:22 2021 +0100
+++ b/trytond/model/modelstorage.py     Sat Feb 13 11:15:16 2021 +0100
@@ -1624,6 +1624,7 @@
                 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 @@
                     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)):

Reply via email to