diff options
| author | Nicolas Seinlet <nse@openerp.com> | 2021-05-05 07:26:52 +0000 |
|---|---|---|
| committer | Nicolas Seinlet <nse@openerp.com> | 2021-05-05 07:26:52 +0000 |
| commit | 091d20d314f8301f0cbec292ec7b6fca906fd39e (patch) | |
| tree | 15055951ccce0ada895cefcd61a13236b756523a | |
| parent | f24ecceae28237e920efb3dd59d5b8d76f550723 (diff) | |
[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#69668
Signed-off-by: Christophe Simonis <chs@odoo.com>
| -rw-r--r-- | addons/gamification/models/challenge.py | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index d72872541d0..3e216165218 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': <challenge line target>, - 'state': <gamification.goal state {draft,inprogress,reached,failed,canceled}>, + 'state': <gamification.goal state {draft,inprogress,reached,failed,canceled}>, 'completeness': <percentage>, 'current': <current value>, } |
