[FIX] mail: prevent crash when initializing many failures

The test highlighting the current issue has been posted in PR
https://github.com/odoo/odoo/pull/62076

But it is not included as part of the current PR because it is too slow to
execute, while it is unlikely we will break this fix as it is not influenced by
anything else in the code.

The reason why we need this change is because on some database, including ours,
we have users who have more than 1000 failures still unresolved and they are
all returned at init.

closes odoo/odoo#62173

X-original-commit: 32ed8125aeb356e568d3c49ef7a04c0ff9e36169
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2020-11-23 12:28:54 +00:00
parent 385a776a1f
commit 5f42a13bfa
@@ -210,17 +210,17 @@ function factory(dependencies) {
* @private
* @param {Object} mailFailuresData
*/
_initMailFailures(mailFailuresData) {
const messages = this.env.models['mail.message'].insert(mailFailuresData.map(
messageData => this.env.models['mail.message'].convertData(messageData)
));
for (const message of messages) {
async _initMailFailures(mailFailuresData) {
await executeGracefully(mailFailuresData.map(messageData => () => {
const message = this.env.models['mail.message'].insert(
this.env.models['mail.message'].convertData(messageData)
);
// implicit: failures are sent by the server at initialization
// only if the current partner is author of the message
if (!message.author && this.messaging.currentPartner) {
message.update({ author: [['link', this.messaging.currentPartner]] });
}
}
}));
this.messaging.notificationGroupManager.computeGroups();
// manually force recompute of counter (after computing the groups)
this.messaging.messagingMenu.update();