[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#89463 X-original-commit: 3a0562ea809b5ba40a66fa4a996424696320f91c Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user