[FIX] orm: _compute_related: ensure prefetch is done in batch
authorOlivier Dony <odo@openerp.com>
Wed, 6 Aug 2014 16:48:35 +0000 (18:48 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 6 Aug 2014 16:48:35 +0000 (18:48 +0200)
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.

openerp/fields.py

index 71ded7c..4cfb287 100644 (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]