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
This commit is contained in:
1 parent
9202f337e3
commit
bc1f29e6c9
1 file changed
+4
-1
@@ -1566,7 +1566,10 @@ class ModelStorage(Model):
|
||||
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']
|
||||
|
||||
Reference in new issue
Block a user