mirror of https://github.com/OCA/social.git
When searching for failed messages, [this line][1] made Odoo search messages in 2 steps:
1. Find which `mail.tracking.email` records are in those states.
2. Find which of them belong to the present `mail.message` records.
Step 2 could take a long time if there were a lot of failures in a DB. In our proven case, this made loading the `res.partner` form view take about ~6s per partner. It was also slowing down other views.
With this simple fix, [that nasty line linked above][1] is solved with just one query like this:
```SQL
SELECT "mail_message".id FROM "mail_tracking_email" as "mail_message__mail_tracking_ids","mail_message"
WHERE ("mail_message"."id"="mail_message__mail_tracking_ids"."maiL_message_id") AND (((("mail_message"."model" = 'res.partner') AND ("mail_message"."mail_tracking_needs_action" = true)) AND ("mail_message__mail_tracking_ids"."state" in ('rejected','error','bounced','soft-bounced','spam'))) AND ("mail_message"."res_id" in (1000)))
ORDER BY "mail_message"."id" DESC
```
Thus this makes the forms load at normal speed again.
[1]:
|
||
---|---|---|
base_search_mail_content | ||
email_template_qweb | ||
fetchmail_thread_default | ||
mail_activity_board | ||
mail_activity_done | ||
mail_activity_partner | ||
mail_activity_reminder | ||
mail_activity_team | ||
mail_attach_existing_attachment | ||
mail_attach_existing_attachment_account | ||
mail_check_mailbox_size | ||
mail_debrand | ||
mail_drop_target | ||
mail_full_expand | ||
mail_inline_css | ||
mail_optional_autofollow | ||
mail_optional_follower_notification | ||
mail_outbound_static | ||
mail_restrict_follower_selection | ||
mail_template_substitute | ||
mail_track_diff_only | ||
mail_tracking | ||
mail_tracking_mailgun | ||
mail_tracking_mass_mailing | ||
mass_mailing_custom_unsubscribe | ||
mass_mailing_custom_unsubscribe_event | ||
mass_mailing_event_registration_exclude | ||
mass_mailing_list_dynamic | ||
mass_mailing_newsletter_welcome_mail | ||
mass_mailing_partner | ||
mass_mailing_resend | ||
mass_mailing_unique | ||
message_auto_subscribe_notify_own | ||
setup | ||
website_mass_mailing_name | ||
.editorconfig | ||
.gitignore | ||
.travis.yml | ||
LICENSE | ||
README.md | ||
oca_dependencies.txt | ||
requirements.txt | ||
test-requirements.txt |