[FIX] mail: improve performance of ringing thread

Avoid iterating over all channels every time a new channel is added.

Part of task-2702450

closes odoo/odoo#81051

X-original-commit: 5359a8c354b0a6106d462fe8f047de946614b7b1
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2021-12-08 12:52:32 +00:00
parent c171ebb054
commit e5ac55cc59
2 changed files with 19 additions and 3 deletions
@@ -356,10 +356,11 @@ registerModel({
*/
publicPartners: many2many('mail.partner'),
/**
* Threads for which the current partner has a pending invitation
* Threads for which the current partner has a pending invitation.
* It is computed from the inverse relation for performance reasons.
*/
ringingThreads: many2many('mail.thread', {
compute: '_computeRingingThreads',
ringingThreads: one2many('mail.thread', {
inverse: 'messagingAsRingingThread',
}),
rtc: one2one('mail.rtc', {
default: insertAndReplace(),
@@ -1536,6 +1536,16 @@ registerModel({
return total + 1;
}, baseCounter);
},
/**
* @private
* @returns {FieldCommand}
*/
_computeMessagingAsRingingThread() {
if (this.rtcInvitingSession) {
return replace(this.messaging);
}
return clear();
},
/**
* @private
* @returns {mail.message[]}
@@ -2162,6 +2172,11 @@ registerModel({
inverse: 'thread',
isCausal: true,
}),
messagingAsRingingThread: many2one('mail.messaging', {
compute: '_computeMessagingAsRingingThread',
inverse: 'ringingThreads',
readonly: true,
}),
model: attr({
readonly: true,
required: true,