[FIX] im_livechat: performance issue: slow to open dashboard of livechat channels

closes odoo/odoo#39154

X-original-commit: 6a08db92769da82023d25d04072027f8a54659b8
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Fabien Pinckaers
2019-10-22 06:49:03 +00:00
committed by fw-bot
parent d987f8137a
commit d99b0e4259
@@ -70,8 +70,10 @@ class ImLivechatChannel(models.Model):
@api.depends('channel_ids')
def _compute_nbr_channel(self):
data = self.env['mail.channel'].read_group([('livechat_channel_id', 'in', self._ids)], ['__count'], ['livechat_channel_id'], lazy=False)
channel_count = {x['livechat_channel_id'][0]: x['__count'] for x in data}
for record in self:
record.nbr_channel = len(record.channel_ids)
record.nbr_channel = channel_count.get(record.id, 0)
# --------------------------
# Action Methods