diff --git a/openerp/models.py b/openerp/models.py index a9babb84126..4dd70e738d6 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -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):