[FIX] core: prefetching of context-dependent fields
Consider a context-dependent field, and successively access it on a recordset with different contexts. On the first context, the field is correctly computed in batch. After that, the field is always computed one by one. The bug is in the method that determines which records in a given set have no value in cache. On the first context, the cache is empty for the field, so all records are returned. After that, the method considers that all records have a value in cache: they do, but for another context key! Simply using the context key when looking up the cache fixes the issue. closes odoo/odoo#52360 X-original-commit: 35d69589d9b43afe6c6fc9779458323f7180153e Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com> Co-authored-by: Xavier-Do <xdo@odoo.com>
This commit is contained in:
committed by
Xavier-Do
co-authored by
Xavier-Do
parent
1d0501d261
commit
6d5da2d2d3
+15
-4
@@ -878,15 +878,26 @@ class Cache(object):
|
||||
|
||||
def get_records(self, model, field):
|
||||
""" Return the records of ``model`` that have a value for ``field``. """
|
||||
ids = list(self._data[field])
|
||||
field_cache = self._data[field]
|
||||
if field.depends_context:
|
||||
key = model.env.cache_key(field)
|
||||
ids = [id_ for id_, value in field_cache.items() if key in value]
|
||||
else:
|
||||
ids = list(field_cache)
|
||||
return model.browse(ids)
|
||||
|
||||
def get_missing_ids(self, records, field):
|
||||
""" Return the ids of ``records`` that have no value for ``field``. """
|
||||
field_cache = self._data[field]
|
||||
for record_id in records._ids:
|
||||
if record_id not in field_cache:
|
||||
yield record_id
|
||||
if field.depends_context:
|
||||
key = records.env.cache_key(field)
|
||||
for record_id in records._ids:
|
||||
if key not in field_cache.get(record_id, ()):
|
||||
yield record_id
|
||||
else:
|
||||
for record_id in records._ids:
|
||||
if record_id not in field_cache:
|
||||
yield record_id
|
||||
|
||||
def invalidate(self, spec=None):
|
||||
""" Invalidate the cache, partially or totally depending on ``spec``. """
|
||||
|
||||
Reference in New Issue
Block a user