[FIX] res.partner: performance of name_get()
Rev. 93e9a4dce7 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!
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user