We are currently lacking an index with (author, failure) due to the information being spread out in two different tables which are both rather big (there are a lot of non-failure messages for the current user, as well as a lot of failure messages for other users), so the fetch of failures for the current user can become extremely slow (> 20s). With this new index, the query takes less than 1ms. task-2742946 closes odoo/odoo#83451 Related: odoo/upgrade#3204 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
39 lines
1.9 KiB
Python
39 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import _, api, fields, models
|
|
|
|
|
|
class MailResendCancel(models.TransientModel):
|
|
_name = 'mail.resend.cancel'
|
|
_description = 'Dismiss notification for resend by model'
|
|
|
|
model = fields.Char(string='Model')
|
|
help_message = fields.Char(string='Help message', compute='_compute_help_message')
|
|
|
|
@api.depends('model')
|
|
def _compute_help_message(self):
|
|
for wizard in self:
|
|
wizard.help_message = _("Are you sure you want to discard %s mail delivery failures? You won't be able to re-send these mails later!") % (wizard._context.get('unread_counter'))
|
|
|
|
def cancel_resend_action(self):
|
|
author_id = self.env.user.partner_id.id
|
|
for wizard in self:
|
|
self._cr.execute("""
|
|
SELECT notif.id, mes.id
|
|
FROM mail_notification notif
|
|
JOIN mail_message mes
|
|
ON notif.mail_message_id = mes.id
|
|
WHERE notif.notification_type = 'email'
|
|
AND notif.author_id = %(author_id)s
|
|
AND notif.notification_status IN ('bounce', 'exception')
|
|
AND mes.model = %(model_name)s
|
|
""", {'model_name': wizard.model, 'author_id': author_id})
|
|
res = self._cr.fetchall()
|
|
notif_ids = [row[0] for row in res]
|
|
messages_ids = list(set([row[1] for row in res]))
|
|
if notif_ids:
|
|
self.env["mail.notification"].browse(notif_ids).sudo().write({'notification_status': 'canceled'})
|
|
self.env["mail.message"].browse(messages_ids)._notify_message_notification_update()
|
|
return {'type': 'ir.actions.act_window_close'}
|