[FIX] prefetch issues on computed fields (#18799)

When deciding to prefetch records (getting records from the cache with no value
for the field being fetched), if the field was computed `determine_value` would
just get all records, not limited by the normal prefetch limit; for large
recordsets this would generate gigantic prefetch lists for records we may not
need at all.

Fix by applying the `PREFETCH_MAX` limit to records from the cache as is done
in `_prefetch_field`.
This commit is contained in:
Raphael Collet 2017-08-11 16:02:27 +02:00 committed by GitHub
parent 40197b38e5
commit 8efeb4c6fc
1 changed files with 8 additions and 8 deletions

View File

@ -3206,9 +3206,6 @@ class BaseModel(object):
# fetch the records of this model without field_name in their cache
records = self._in_cache_without(field)
if len(records) > PREFETCH_MAX:
records = records[:PREFETCH_MAX] | self
# determine which fields can be prefetched
if not self.env.in_draft and \
self._context.get('prefetch_fields', True) and \
@ -5675,16 +5672,19 @@ class BaseModel(object):
return RecordCache(self)
@api.model
def _in_cache_without(self, field):
""" Make sure ``self`` is present in cache (for prefetching), and return
the records of model ``self`` in cache that have no value for ``field``
(:class:`Field` instance).
def _in_cache_without(self, field, limit=PREFETCH_MAX):
""" Return records to prefetch that have no value in cache for ``field``
(:class:`Field` instance), including ``self``.
Return at most ``limit`` records.
"""
env = self.env
prefetch_ids = env.prefetch[self._name]
prefetch_ids.update(self._ids)
ids = filter(None, prefetch_ids - set(env.cache[field]))
return self.browse(ids)
recs = self.browse(ids)
if limit and len(recs) > limit:
recs = self + (recs - self)[:(limit - len(self))]
return recs
@api.model
def refresh(self):