[FIX] mail, im_livechat: fix perf of thread sorting
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) <aku@odoo.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user