[IMP] gamification: improve 40e8437
to make only one global request
This commit is contained in:
parent
40e843761f
commit
b707719891
|
@ -95,18 +95,21 @@ class gamification_badge(osv.Model):
|
||||||
the total number of time this badge was granted
|
the total number of time this badge was granted
|
||||||
the total number of users this badge was granted to
|
the total number of users this badge was granted to
|
||||||
"""
|
"""
|
||||||
result = dict.fromkeys(ids, False)
|
result = dict.fromkeys(ids, {'stat_count':0, 'stat_count_distinct':0, 'unique_owner_ids':[]})
|
||||||
for badge_id in ids:
|
|
||||||
cr.execute("""
|
cr.execute("""
|
||||||
SELECT user_id
|
SELECT badge_id, count(user_id) as stat_count,
|
||||||
|
count(distinct(user_id)) as stat_count_distinct,
|
||||||
|
array_agg(distinct(user_id)) as unique_owner_ids
|
||||||
FROM gamification_badge_user
|
FROM gamification_badge_user
|
||||||
WHERE badge_id = %s
|
WHERE badge_id in %s
|
||||||
""", (badge_id,))
|
GROUP BY badge_id
|
||||||
res = [user_id[0] for user_id in cr.fetchall()]
|
""", (tuple(ids),))
|
||||||
|
for (badge_id, stat_count, stat_count_distinct, unique_owner_ids) in cr.fetchall():
|
||||||
result[badge_id] = {
|
result[badge_id] = {
|
||||||
'unique_owner_ids': list(set(res)),
|
'stat_count': stat_count,
|
||||||
'stat_count': len(res),
|
'stat_count_distinct': stat_count_distinct,
|
||||||
'stat_count_distinct': len(list(set(res)))
|
'unique_owner_ids': unique_owner_ids,
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue