From af1a8758ec303dd5b0c30b44d06eac29bfc82ec9 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 2 Jun 2016 21:14:50 +0200 Subject: [PATCH] [FIX] res.partner: performance of name_get() Rev. 93e9a4dce7550af5cecab398670a4a53ea41f130 tried to speed up the 9.0 name_get() of res.partner by only calling fields_get() once for the whole name_get, instead of calling it lazily. This may have worked for name_get calls on multiple unnamed addresses (name is NULL), but this is a rare occurrence in practice - while now every single name_get() call would incur the full cost of the fields_get() call. That fields_get() call is O(n) in the number of fields, and there can be quite a few for res.partner. Calling it only for the specific 'type' field can easily be about 40x faster than without it. And since name_get() is called for each Many2One field of each record being read (due to convert_to_read()), reading a batch of records with partner fields had become quite a bit slower! Avoiding this cost entirely with lazy fields_get() calls saves quite a lot of time for the common cases. And now that fields_get() specifies a single field, it is cheap enough to be called within the loop. Non-scientific benchmark: account.invoice.search_read() in the list view of invoices took 500ms for 25 invoices _before_ this fix, and 90ms after! --- openerp/addons/base/res/res_partner.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 0e21b3272dc..f832a90eb2a 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -563,12 +563,11 @@ class res_partner(osv.Model, format_address): if isinstance(ids, (int, long)): ids = [ids] res = [] - types_dict = dict(self.fields_get(cr, uid, context=context)['type']['selection']) for record in self.browse(cr, uid, ids, context=context): name = record.name or '' if record.parent_id and not record.is_company: if not name and record.type in ['invoice', 'delivery', 'other']: - name = types_dict[record.type] + name = dict(self.fields_get(cr, uid, ['type'], context=context)['type']['selection'])[record.type] name = "%s, %s" % (record.parent_name, name) if context.get('show_address_only'): name = self._display_address(cr, uid, record, without_company=True, context=context)