FEATURE: new badges when visiting the forum for 10, 100 and 365 consecutive days

This commit is contained in:
Régis Hanol
2017-09-06 22:35:08 +02:00
parent 0fca5ed533
commit 8a935a4b5f
4 changed files with 47 additions and 0 deletions

View File

@ -232,4 +232,16 @@ SQL
SQL
end
def self.consecutive_visits(days)
<<~SQL
SELECT user_id, "start" + interval '1' day * COUNT(*) AS "granted_at"
FROM (
SELECT user_id, visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int "start"
FROM user_visits
) s
GROUP BY user_id, "start"
HAVING COUNT(*) >= #{days}
SQL
end
end