Skip to content
Snippets Groups Projects
Commit 3a0562ea authored by Fabio Barbero's avatar Fabio Barbero
Browse files

[IMP] gamification: improve performance of ranks


Purpose
=======
Avoid calling _recompute_rank for users that are not affected by the
newly created/written ranks, by filtering users by karma_min

Task-2746929

closes odoo/odoo#83916

Signed-off-by: default avatarWarnon Aurélien (awa) <awa@odoo.com>
parent 5dc3b3ef
No related branches found
No related tags found
No related merge requests found
......@@ -35,8 +35,10 @@ class KarmaRank(models.Model):
@api.model_create_multi
def create(self, values_list):
res = super(KarmaRank, self).create(values_list)
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
users._recompute_rank()
if any(res.mapped('karma_min')) > 0:
users = self.env['res.users'].sudo().search([('karma', '>=', max(min(res.mapped('karma_min')), 1))])
if users:
users._recompute_rank()
return res
def write(self, vals):
......@@ -50,8 +52,8 @@ class KarmaRank(models.Model):
if 'karma_min' in vals:
after_ranks = self.env['gamification.karma.rank'].search([], order="karma_min DESC").ids
if previous_ranks != after_ranks:
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
users = self.env['res.users'].sudo().search([('karma', '>=', max(low, 1))])
else:
users = self.env['res.users'].sudo().search([('karma', '>=', low), ('karma', '<=', high)])
users = self.env['res.users'].sudo().search([('karma', '>=', max(low, 1)), ('karma', '<=', high)])
users._recompute_rank()
return res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment