[FIX] mail: performance in find_partner_from_email
This is a backport of commit 3d32e9966500290f35e6edfebf97b9a60a1fc495 done in 9 and ported to the old API. The purpose is to avoid searching on the res.partner table with a domain leaf being user_ids != False. Indeed this search is costly. Use a direct search on the user table instead.
This commit is contained in:
parent
3f758e2fab
commit
345f393ac0
|
@ -1470,6 +1470,7 @@ class mail_thread(osv.AbstractModel):
|
|||
:param boolean check_followers: check in document followers
|
||||
"""
|
||||
partner_obj = self.pool['res.partner']
|
||||
users_obj = self.pool['res.users']
|
||||
partner_ids = []
|
||||
obj = None
|
||||
if id and (model or self._name != 'mail.thread') and check_followers:
|
||||
|
@ -1495,16 +1496,15 @@ class mail_thread(osv.AbstractModel):
|
|||
email_brackets = "<%s>" % email_address
|
||||
if not partner_id:
|
||||
# exact, case-insensitive match
|
||||
ids = partner_obj.search(cr, SUPERUSER_ID,
|
||||
[('email', '=ilike', email_address),
|
||||
('user_ids', '!=', False)],
|
||||
user_ids = users_obj.search(cr, SUPERUSER_ID,
|
||||
[('email', '=ilike', email_address)],
|
||||
limit=1, context=context)
|
||||
ids = [users_obj.browse(cr, SUPERUSER_ID, user_ids, context=context).partner_id.id]
|
||||
if not ids:
|
||||
# if no match with addr-spec, attempt substring match within name-addr pair
|
||||
ids = partner_obj.search(cr, SUPERUSER_ID,
|
||||
[('email', 'ilike', email_brackets),
|
||||
('user_ids', '!=', False)],
|
||||
limit=1, context=context)
|
||||
user_ids = users_obj.search(cr, SUPERUSER_ID,
|
||||
[('email', 'ilike', email_brackets)], limit=1, context=context)
|
||||
ids = [users_obj.browse(cr, SUPERUSER_ID, user_ids, context=context).partner_id.id]
|
||||
if ids:
|
||||
partner_id = ids[0]
|
||||
# third try: check in partners
|
||||
|
|
Loading…
Reference in New Issue