mail: 'Send a message' generates excessively slow queries

Bug #1311087 reported by Guewen Baconnier @ Camptocamp
38
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
New
Undecided
OpenERP Publisher's Warranty Team
OpenERP Community Backports (Addons)
Status tracked in 7.0
7.0
Fix Committed
Undecided
Unassigned

Bug Description

Using the "Send a message" action on a model having a mail.thread, I notice a very long delay (8-10 seconds) before the action is done.

I used the debug_sql log level and could see that this slowness is due to the queries generated by the ORM.

In the `mail_message` module, in `mail_message._notify`, we can see this query:

            fol_ids = fol_obj.search(cr, SUPERUSER_ID, [
                ('res_model', '=', message.model),
                ('res_id', '=', message.res_id),
                ('subtype_ids', 'in', message.subtype_id.id)
                ], context=context)

Which results in:
2014-04-22 14:00:05 CEST LOG: duration: 1138.682 ms statement: SELECT "mail_followers_id" FROM "mail_followers_mail_message_subtype_rel" WHERE "mail_message_subtype_id" IN (1)
2014-04-22 14:00:21 CEST LOG: duration: 2544.561 ms statement: SELECT "mail_followers".id FROM "mail_followers" WHERE ((("mail_followers"."res_model" = 'crm.claim') AND ("mail_followers"."res_id" = 894)) AND ("mail_followers"."id" in (1,2,3,4,5, .....))) ORDER BY "mail_followers"."id"
where (1,2,3,4,5, .....) contains the IDs returned by the first statement (2.500.000 ids here).

Same result could be done with a query using JOINs:

SELECT mail_followers.id
FROM mail_followers
INNER JOIN mail_followers_mail_message_subtype_rel rel
ON rel.mail_followers_id = mail_followers.id
WHERE mail_followers.res_model = 'crm.claim'
AND mail_followers.res_id = 894
AND rel.mail_message_subtype_id = 1
ORDER BY mail_followers.id

Then, it takes merely a millisecond instead of several seconds.

Tags: maintenance

Related branches

Changed in openobject-addons:
assignee: nobody → OpenERP Publisher's Warranty Team (openerp-opw)
tags: added: maintenance
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.