[FIX] mail: fix performance issue with im status tracking

Move compute of `imStatusTrackedPersonas` to its inverse field. Doing
the compute on the "One" side of the relation prevents from looping and
computing all values whenever there is a change in any of them.

In practice, this reduces the "compute" time of the message fetch (which
also fetch persona as authors of messages), reducing by approximately
half the time it takes to insert these messages (depending on the number
of persona it had to loop through).

For example from 60ms to 30ms on my machine for message insert in
"partner_1_125" (populate medium).

closes odoo/odoo#154918

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2024-02-21 17:27:50 +00:00
parent 618cc9cc88
commit df8484e833
2 changed files with 11 additions and 9 deletions
@@ -34,6 +34,16 @@ export class Persona extends Record {
landlineNumber;
/** @type {string} */
mobileNumber;
storeAsTrackedImStatus = Record.one("Store", {
/** @this {import("models").Persona} */
compute() {
if (this.type === "partner" && this.im_status !== "im_partner" && !this.is_public) {
return this._store;
}
},
eager: true,
inverse: "imStatusTrackedPersonas",
});
/** @type {'partner' | 'guest'} */
type;
/** @type {string} */
@@ -74,18 +74,10 @@ export class Store extends BaseStore {
users = {};
internalUserGroupId = null;
imStatusTrackedPersonas = Record.many("Persona", {
compute() {
return Object.values(this.Persona?.records ?? []).filter(
(persona) =>
persona.type === "partner" &&
persona.im_status !== "im_partner" &&
!persona.is_public
);
},
inverse: "storeAsTrackedImStatus",
onUpdate() {
this.updateImStatusRegistration();
},
eager: true,
});
hasLinkPreviewFeature = true;
// messaging menu