[FIX] mail: batch update of followers/recipients
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) <seb@odoo.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user