[IMP] mail_message: avoid doing search criterions on subtype_ids, takes long time
[odoo/odoo.git] / addons / mail / mail_message.py
index eca19d5..dce5ed1 100644 (file)
@@ -840,8 +840,7 @@ class mail_message(osv.Model):
             values['record_name'] = self._get_record_name(cr, uid, values, context=context)
 
         newid = super(mail_message, self).create(cr, uid, values, context)
-        if not values.get('subtype_id'):
-            return newid
+
         self._notify(cr, uid, newid, context=context,
                      force_send=context.get('mail_notify_force_send', True),
                      user_signature=context.get('mail_notify_user_signature', True))
@@ -902,9 +901,11 @@ class mail_message(osv.Model):
                 cr, SUPERUSER_ID, [
                     ('res_model', '=', message.model),
                     ('res_id', '=', message.res_id),
-                    ('subtype_ids', 'in', message.subtype_id.id)
                 ], context=context)
-            partners_to_notify |= set(fo.partner_id.id for fo in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context))
+            partners_to_notify |= set(
+                fo.partner_id.id for fo in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context)
+                if message.subtype_id.id in [st.id for st in fo.subtype_ids]
+            )
         # remove me from notified partners, unless the message is written on my own wall
         if message.subtype_id and message.author_id and message.model == "res.partner" and message.res_id == message.author_id.id:
             partners_to_notify |= set([message.author_id.id])