From 6d14689280eeec342d3f036858356e766607a982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 15 Dec 2023 18:11:25 +0100 Subject: [PATCH] [FIX] mail, im_livechat: fix perf of thread sorting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make correspondent a compute to benefit from cache. This reduces the time on populate medium from around 600ms to 200ms. closes odoo/odoo#146109 Related: odoo/enterprise#52703 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/core/web/thread_model_patch.js | 4 ++-- addons/mail/static/src/core/common/thread_model.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/im_livechat/static/src/core/web/thread_model_patch.js b/addons/im_livechat/static/src/core/web/thread_model_patch.js index 96baeca8e86..55028d97453 100644 --- a/addons/im_livechat/static/src/core/web/thread_model_patch.js +++ b/addons/im_livechat/static/src/core/web/thread_model_patch.js @@ -25,8 +25,8 @@ patch(Thread.prototype, { return super.correspondents.filter((correspondent) => !correspondent.is_bot); }, - get correspondent() { - let correspondent = super.correspondent; + computeCorrespondent() { + let correspondent = super.computeCorrespondent(); if (this.type === "livechat" && !correspondent) { // For livechat threads, the correspondent is the first // channel member that is not the operator. diff --git a/addons/mail/static/src/core/common/thread_model.js b/addons/mail/static/src/core/common/thread_model.js index 633983cb580..f9e46e2cce0 100644 --- a/addons/mail/static/src/core/common/thread_model.js +++ b/addons/mail/static/src/core/common/thread_model.js @@ -186,6 +186,11 @@ export class Thread extends Record { invitedMembers = Record.many("ChannelMember"); chatPartner = Record.one("Persona"); composer = Record.one("Composer", { inverse: "thread", onDelete: (r) => r.delete() }); + correspondent2 = Record.one("Persona", { + compute() { + return this.computeCorrespondent(); + }, + }); counter = 0; /** @type {string} */ custom_channel_name; @@ -360,8 +365,11 @@ export class Thread extends Record { .filter((p) => p.notEq(this._store.self)); } - /** @type {import("models").Persona|undefined} */ get correspondent() { + return this.correspondent2; + } + + computeCorrespondent() { if (this.type === "channel") { return undefined; }