[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 <chs@odoo.com>
This commit is contained in:
@@ -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>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user