[FIX] orm: _compute_related: ensure prefetch is done in batch

Due to the use of a sudo env, the records
were being added to the sudo cache one by
one instead of all at once. This meant the
prefetching was not able to load all
records at once, leading to prohibitive
times when processing thousands of
records.
This commit is contained in:
Olivier Dony 2014-08-06 18:48:35 +02:00
parent 135962184d
commit f062eec639
1 changed files with 2 additions and 2 deletions

View File

@ -418,9 +418,9 @@ class Field(object):
def _compute_related(self, records):
""" Compute the related field `self` on `records`. """
for record in records:
for record, sudo_record in zip(records, records.sudo()):
# bypass access rights check when traversing the related path
value = record.sudo() if record.id else record
value = sudo_record if record.id else record
# traverse the intermediate fields, and keep at most one record
for name in self.related[:-1]:
value = value[name][:1]