changeset acdbdcac6687 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=acdbdcac6687
description:
        Use the ids order to fill cache with read data

        The shared cache is designed for loop usage so we must ensure that we 
fill the
        LRU dictionary in the same order as the loop will request attributes.
        So we must order the result of the read because the API does not return 
data in
        the same order as the list of ids.

        issue9518
        review318041002
diffstat:

 trytond/model/modelstorage.py |  5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diffs (15 lines):

diff -r 32148996668f -r acdbdcac6687 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py     Sat Jul 25 08:03:02 2020 +0200
+++ b/trytond/model/modelstorage.py     Mon Aug 10 23:24:02 2020 +0200
@@ -1566,7 +1566,10 @@
                     for i in ids
                     if i in self._cache and name in self._cache[i]]
             else:
-                read_data = self.read(list(ids), list(ffields.keys()))
+                # Order data read to update cache in the same order
+                index = {i: n for n, i in enumerate(ids)}
+                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
             for data in read_data:
                 id_ = data['id']

Reply via email to