[FIX] mail: improve messaging menu performance

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) <aku@odoo.com>
This commit is contained in:
Didier (did)
2023-10-24 15:23:22 +00:00
parent 3b11745923
commit ea0071ffc7
@@ -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 ||