From 4f5d36a464fa7f1a4536677f0b5e12fd20841acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 5 Dec 2013 10:39:21 +0100 Subject: [PATCH] [IMP] [CLEAN] mail: mail_thread: routing - removed a debug print statement - now searching all references once instead of each reference one at a time to lessen the number of queries; as the newest message will be the first in the search result, it's ok. bzr revid: tde@openerp.com-20131205093921-h7sits57vqc51c8p --- addons/mail/mail_thread.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index f69cbdbefc0..8eb85ba814d 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -834,19 +834,18 @@ class mail_thread(osv.AbstractModel): # 1. message is a reply to an existing message (exact match of message_id) msg_references = thread_references.split() - for msg_reference in msg_references: - mail_message_ids = mail_msg_obj.search(cr, uid, [('message_id', '=', msg_reference)], context=context) - if mail_message_ids: - original_msg = mail_msg_obj.browse(cr, SUPERUSER_ID, mail_message_ids[0], context=context) - model, thread_id = original_msg.model, original_msg.res_id - _logger.info( - 'Routing mail from %s to %s with Message-Id %s: direct reply to msg: model: %s, thread_id: %s, custom_values: %s, uid: %s', - email_from, email_to, message_id, model, thread_id, custom_values, uid) - route = self.message_route_verify( - cr, uid, message, message_dict, - (model, thread_id, custom_values, uid, None), - update_author=True, assert_model=True, create_fallback=True, context=context) - return route and [route] or [] + mail_message_ids = mail_msg_obj.search(cr, uid, [('message_id', 'in', msg_references)], context=context) + if mail_message_ids: + original_msg = mail_msg_obj.browse(cr, SUPERUSER_ID, mail_message_ids[0], context=context) + model, thread_id = original_msg.model, original_msg.res_id + _logger.info( + 'Routing mail from %s to %s with Message-Id %s: direct reply to msg: model: %s, thread_id: %s, custom_values: %s, uid: %s', + email_from, email_to, message_id, model, thread_id, custom_values, uid) + route = self.message_route_verify( + cr, uid, message, message_dict, + (model, thread_id, custom_values, uid, None), + update_author=True, assert_model=True, create_fallback=True, context=context) + return route and [route] or [] # 2. message is a reply to an existign thread (6.1 compatibility) ref_match = thread_references and tools.reference_re.search(thread_references) @@ -861,7 +860,6 @@ class mail_thread(osv.AbstractModel): ('model', '=', model), ('res_id', '=', thread_id), ], context=context) - print 'cacaprout', compat_mail_msg_ids if compat_mail_msg_ids and model_obj.exists(cr, uid, thread_id) and hasattr(model_obj, 'message_update'): _logger.info( 'Routing mail from %s to %s with Message-Id %s: direct thread reply (compat-mode) to model: %s, thread_id: %s, custom_values: %s, uid: %s',