From ea0071ffc76171b220e9556dd00933b8e30c3ff6 Mon Sep 17 00:00:00 2001 From: "Didier (did)" Date: Thu, 19 Oct 2023 13:24:27 +0000 Subject: [PATCH] [FIX] mail: improve messaging menu performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To reproduce: * Populate mail.message as medium or more * Open odoo and click the messaging menu * The messaging menu take an unreasonable amount of time to open. This PR cache the threads getter to avoid unnecessary computations task-3551625 closes odoo/odoo#139519 X-original-commit: aa92a630d5146b7a4ee5eb5d09bb6db04c1ba146 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/core/web/messaging_menu.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mail/static/src/core/web/messaging_menu.js b/addons/mail/static/src/core/web/messaging_menu.js index ecf281b7731..67062e8a430 100644 --- a/addons/mail/static/src/core/web/messaging_menu.js +++ b/addons/mail/static/src/core/web/messaging_menu.js @@ -4,7 +4,7 @@ import { ImStatus } from "@mail/core/common/im_status"; import { NotificationItem } from "@mail/core/web/notification_item"; import { onExternalClick } from "@mail/utils/common/hooks"; -import { Component, useState } from "@odoo/owl"; +import { Component, onWillRender, useState } from "@odoo/owl"; import { hasTouch } from "@web/core/browser/feature_detection"; import { Dropdown } from "@web/core/dropdown/dropdown"; @@ -34,6 +34,7 @@ export class MessagingMenu extends Component { onExternalClick("selector", () => { Object.assign(this.state, { addingChat: false, addingChannel: false }); }); + onWillRender(() => (this.threads = this.getThreads())); } beforeOpen() { @@ -103,14 +104,13 @@ export class MessagingMenu extends Component { displayName: _t("%s has a request", this.store.odoobot.name), iconSrc: this.threadService.avatarUrl(this.store.odoobot), partner: this.store.odoobot, - isLast: this.threads.length === 0 && this.store.failures.length === 0, isShown: this.store.discuss.activeTab === "all" && this.notification.permission === "prompt", }; } - get threads() { - /** @type {import("models").Thread[]} */ + getThreads() { + /** @type {import("@mail/core/common/thread_model").Thread[]} */ let threads = Object.values(this.store.Thread.records).filter( (thread) => thread.is_pinned ||