From acf306e4fb5185ed9e112267ca10911ca2ca28ed Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Wed, 5 May 2021 07:26:52 +0000 Subject: [PATCH] [IMP] gamification: skip useless computations - use real join - skip useless join on res_users and gamification_challenge - skip null end_date criteria to compute less reached goal closes odoo/odoo#70503 X-original-commit: 091d20d314f8301f0cbec292ec7b6fca906fd39e Signed-off-by: Christophe Simonis --- addons/gamification/models/challenge.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index 637dbe1f03d..a62c4d2dc47 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -245,19 +245,13 @@ class Challenge(models.Model): # exclude goals for users that did not connect since the last update yesterday = fields.Date.to_string(date.today() - timedelta(days=1)) self.env.cr.execute("""SELECT gg.id - FROM gamification_goal as gg, - gamification_challenge as gc, - res_users as ru, - res_users_log as log - WHERE gg.challenge_id = gc.id - AND gg.user_id = ru.id - AND ru.id = log.create_uid - AND gg.write_date < log.create_date + FROM gamification_goal as gg + JOIN res_users_log as log ON gg.user_id = log.create_uid + WHERE gg.write_date < log.create_date AND gg.closed IS NOT TRUE - AND gc.id IN %s + AND gg.challenge_id IN %s AND (gg.state = 'inprogress' - OR (gg.state = 'reached' - AND (gg.end_date >= %s OR gg.end_date IS NULL))) + OR (gg.state = 'reached' AND gg.end_date >= %s)) GROUP BY gg.id """, [tuple(self.ids), yesterday]) @@ -360,7 +354,7 @@ class Challenge(models.Model): participant_user_ids = set(challenge.user_ids.ids) user_squating_challenge_ids = user_with_goal_ids - participant_user_ids if user_squating_challenge_ids: - # users that used to match the challenge + # users that used to match the challenge Goals.search([ ('challenge_id', '=', challenge.id), ('user_id', 'in', list(user_squating_challenge_ids)) @@ -451,7 +445,7 @@ class Challenge(models.Model): 'action': <{True,False}>, 'display_mode': <{progress,boolean}>, 'target': , - 'state': , + 'state': , 'completeness': , 'current': , }