From ef37c56251cba7830287e4aa22ab224d42da6ecd Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 20 Jun 2013 16:02:50 +0200 Subject: [PATCH] [FIX] OPW 592482: browse_record should not prefetch binary fields This was apparently a long-standing issue due to a strange handling of the _prefetch attribute on columns: accessing a column would only trigger the prefetching if its _prefetch attribute was True, but the prefetching itself would also prefetch columns that had _prefetch False. We clearly want it the other way around, or at least we want _prefetch to decide whether a column is included in any given prefetching pass. We can skip the prefetching pass when the only field being accessed has _prefetch False because it is likely the other fields have already been prefetched separately. This last subtlety should not make any noticeable performance difference. lp bug: https://launchpad.net/bugs/1177965 fixed bzr revid: odo@openerp.com-20130620140250-z4z0m0t5auviy6w2 --- openerp/osv/fields.py | 2 ++ openerp/osv/orm.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 04228f5..976d6a5 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -1065,6 +1065,8 @@ class function(_column): self._classic_write = True if type=='binary': self._symbol_get=lambda x:x and str(x) + else: + self._prefetch = True if type == 'float': self._symbol_c = float._symbol_c diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index ad6f0bc..62afd4f 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -377,11 +377,11 @@ class browse_record(object): # if the field is a classic one or a many2one, we'll fetch all classic and many2one fields if col._prefetch: # gen the list of "local" (ie not inherited) fields which are classic or many2one - fields_to_fetch = filter(lambda x: x[1]._classic_write, self._table._columns.items()) + fields_to_fetch = filter(lambda x: x[1]._classic_write and x[1]._prefetch, self._table._columns.items()) # gen the list of inherited fields inherits = map(lambda x: (x[0], x[1][2]), self._table._inherit_fields.items()) # complete the field list with the inherited fields which are classic or many2one - fields_to_fetch += filter(lambda x: x[1]._classic_write, inherits) + fields_to_fetch += filter(lambda x: x[1]._classic_write and x[1]._prefetch, inherits) # otherwise we fetch only that field else: fields_to_fetch = [(name, col)] -- 1.7.10.4