[IMP] models: move prefetching of records back to method _prefetch_field

The selection of records in cache for prefetching was moved to method
_read_from_database() by xmo at rev 785018cc in order to fix an access right
bug.  But this introduced an issue: to explicitly avoid prefetching, you should
use read() instead of browsing records.  We revert the change by xmo, without
reintroducing the bug (which apparently was fixed by another way).
This commit is contained in:
Raphael Collet 2014-08-19 15:45:18 +02:00
parent 78a9a6fcaa
commit 97256fa1fb
2 changed files with 4 additions and 18 deletions

View File

@ -1581,12 +1581,6 @@ class calendar_event(osv.Model):
select = [ids]
else:
select = ids
# FIXME: find a better way to not push virtual ids in the cache
# (leading to their prefetching and ultimately a type error when
# postgres tries to convert '14-3489274297' to an integer)
self.invalidate_cache(cr, uid, context=context)
select = map(lambda x: (x, calendar_id2real_id(x)), select)
result = []
real_data = super(calendar_event, self).read(cr, uid, [real_id for calendar_id, real_id in select], fields=fields2, context=context, load=load)

View File

@ -3122,7 +3122,7 @@ class BaseModel(object):
instance) for `self` in cache.
"""
# fetch the records of this model without field_name in their cache
records = self
records = self._in_cache_without(field)
# by default, simply fetch field
fnames = {field.name}
@ -3198,16 +3198,8 @@ class BaseModel(object):
'order': self._parent_order or self._order,
}
empty = self.browse()
prefetch = set()
todo = set()
for field in (self._fields[name] for name in field_names):
prefetch.update(self._in_cache_without(field).ids)
todo.update(self.env.todo.get(field, empty).ids)
records = self.browse(prefetch - todo | set(self.ids))
result = []
for sub_ids in cr.split_for_in_conditions(records.ids):
for sub_ids in cr.split_for_in_conditions(self.ids):
cr.execute(query, [tuple(sub_ids)] + rule_params)
result.extend(cr.dictfetchall())
@ -3280,9 +3272,9 @@ class BaseModel(object):
# store failed values in cache for the records that could not be read
fetched = self.browse(ids)
missing = records - fetched
missing = self - fetched
if missing:
extras = fetched - records
extras = fetched - self
if extras:
raise AccessError(
_("Database fetch misses ids ({}) and has extra ids ({}), may be caused by a type incoherence in a previous request").format(