[IMP] account_report_company: performance on partner name_search
The field display_name is present in account_report_company but not in base on the res.partner (has been added in v8 in base). Create a hook method to keep using the slow CASE in base and switch to the faster display_name when installing account_report_company.
This commit is contained in:
parent
2326bb7a54
commit
f2c807d99d
|
@ -43,6 +43,11 @@ class res_partner(osv.Model):
|
||||||
'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers, select=1),
|
'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers, select=1),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _get_display_name(self, unaccent):
|
||||||
|
# use stored display name for better performances
|
||||||
|
return unaccent('res_partner.display_name')
|
||||||
|
|
||||||
|
|
||||||
class account_invoice(osv.Model):
|
class account_invoice(osv.Model):
|
||||||
_inherit = 'account.invoice'
|
_inherit = 'account.invoice'
|
||||||
|
|
||||||
|
|
|
@ -622,6 +622,20 @@ class res_partner(osv.osv, format_address):
|
||||||
return super(res_partner, self)._search(cr, user, args, offset=offset, limit=limit, order=order, context=context,
|
return super(res_partner, self)._search(cr, user, args, offset=offset, limit=limit, order=order, context=context,
|
||||||
count=count, access_rights_uid=access_rights_uid)
|
count=count, access_rights_uid=access_rights_uid)
|
||||||
|
|
||||||
|
def _get_display_name(self, unaccent):
|
||||||
|
# TODO: simplify this in trunk with `display_name`, once it is stored
|
||||||
|
# Perf note: a CTE expression (WITH ...) seems to have an even higher cost
|
||||||
|
# than this query with duplicated CASE expressions. The bulk of
|
||||||
|
# the cost is the ORDER BY, and it is inevitable if we want
|
||||||
|
# relevant results for the next step, otherwise we'd return
|
||||||
|
# a random selection of `limit` results.
|
||||||
|
|
||||||
|
return """CASE WHEN company.id IS NULL OR res_partner.is_company
|
||||||
|
THEN {partner_name}
|
||||||
|
ELSE {company_name} || ', ' || {partner_name}
|
||||||
|
END""".format(partner_name=unaccent('res_partner.name'),
|
||||||
|
company_name=unaccent('company.name'))
|
||||||
|
|
||||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
|
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
|
||||||
if not args:
|
if not args:
|
||||||
args = []
|
args = []
|
||||||
|
@ -642,18 +656,7 @@ class res_partner(osv.osv, format_address):
|
||||||
|
|
||||||
unaccent = get_unaccent_wrapper(cr)
|
unaccent = get_unaccent_wrapper(cr)
|
||||||
|
|
||||||
# TODO: simplify this in trunk with `display_name`, once it is stored
|
display_name = self._get_display_name(unaccent)
|
||||||
# Perf note: a CTE expression (WITH ...) seems to have an even higher cost
|
|
||||||
# than this query with duplicated CASE expressions. The bulk of
|
|
||||||
# the cost is the ORDER BY, and it is inevitable if we want
|
|
||||||
# relevant results for the next step, otherwise we'd return
|
|
||||||
# a random selection of `limit` results.
|
|
||||||
|
|
||||||
display_name = """CASE WHEN company.id IS NULL OR res_partner.is_company
|
|
||||||
THEN {partner_name}
|
|
||||||
ELSE {company_name} || ', ' || {partner_name}
|
|
||||||
END""".format(partner_name=unaccent('res_partner.name'),
|
|
||||||
company_name=unaccent('company.name'))
|
|
||||||
|
|
||||||
query = """SELECT res_partner.id
|
query = """SELECT res_partner.id
|
||||||
FROM res_partner
|
FROM res_partner
|
||||||
|
|
Loading…
Reference in New Issue