From 22dc25d08e3294c40806b71ccf8bd5d47347bd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 7 Dec 2023 15:51:24 +0100 Subject: [PATCH] [FIX] mail: batch update of followers/recipients MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test "Load 100 recipients at once" goes from 2500ms to 1200ms on my machine. closes odoo/odoo#145442 Signed-off-by: Sébastien Theys (seb) --- .../src/core/web/thread_service_patch.js | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/addons/mail/static/src/core/web/thread_service_patch.js b/addons/mail/static/src/core/web/thread_service_patch.js index 87ef909ed45..ed96a39ab0d 100644 --- a/addons/mail/static/src/core/web/thread_service_patch.js +++ b/addons/mail/static/src/core/web/thread_service_patch.js @@ -5,6 +5,7 @@ import { parseEmail } from "@mail/js/utils"; import { _t } from "@web/core/l10n/translation"; import { patch } from "@web/core/utils/patch"; +import { Record } from "@mail/core/common/record"; let nextId = 1; @@ -75,15 +76,17 @@ patch(ThreadService.prototype, { thread.selfFollower = { followedThread: thread, ...result.selfFollower }; } thread.followersCount = result.followersCount; - for (const followerData of result.followers) { - const follower = this.store.Follower.insert({ - followedThread: thread, - ...followerData, - }); - if (follower.notEq(thread.selfFollower)) { - thread.followers.add(follower); + Record.MAKE_UPDATE(() => { + for (const followerData of result.followers) { + const follower = this.store.Follower.insert({ + followedThread: thread, + ...followerData, + }); + if (follower.notEq(thread.selfFollower)) { + thread.followers.add(follower); + } } - } + }); thread.recipientsCount = result.recipientsCount; for (const recipientData of result.recipients) { thread.recipients.add({ followedThread: thread, ...recipientData }); @@ -157,15 +160,17 @@ patch(ThreadService.prototype, { [thread.id], thread.followers.at(-1).id, ]); - for (const data of followers) { - const follower = this.store.Follower.insert({ - followedThread: thread, - ...data, - }); - if (follower.notEq(thread.selfFollower)) { - thread.followers.add(follower); + Record.MAKE_UPDATE(() => { + for (const data of followers) { + const follower = this.store.Follower.insert({ + followedThread: thread, + ...data, + }); + if (follower.notEq(thread.selfFollower)) { + thread.followers.add(follower); + } } - } + }); }, async loadMoreRecipients(thread) { const recipients = await this.orm.call( @@ -174,9 +179,11 @@ patch(ThreadService.prototype, { [[thread.id], thread.recipients.at(-1).id], { filter_recipients: true } ); - for (const data of recipients) { - thread.recipients.add({ followedThread: thread, ...data }); - } + Record.MAKE_UPDATE(() => { + for (const data of recipients) { + thread.recipients.add({ followedThread: thread, ...data }); + } + }); }, open(thread, replaceNewMessageChatWindow) { if (!this.store.discuss.isActive && !this.ui.isSmall) {