fix badges SQL
This commit is contained in:
parent
56f8327234
commit
29f744e410
|
@ -3,14 +3,13 @@
|
||||||
first_solution_query = <<~SQL
|
first_solution_query = <<~SQL
|
||||||
SELECT post_id, user_id, created_at AS granted_at
|
SELECT post_id, user_id, created_at AS granted_at
|
||||||
FROM (
|
FROM (
|
||||||
SELECT p.id AS post_id, p.user_id, pcf.created_at,
|
SELECT p.id AS post_id, p.user_id, dss.created_at,
|
||||||
ROW_NUMBER() OVER (PARTITION BY p.user_id ORDER BY pcf.created_at) AS row_number
|
ROW_NUMBER() OVER (PARTITION BY p.user_id ORDER BY dss.created_at) AS row_number
|
||||||
FROM post_custom_fields pcf
|
FROM discourse_solved_solutions dss
|
||||||
JOIN badge_posts p ON pcf.post_id = p.id
|
JOIN badge_posts p ON dss.answer_post_id = p.id
|
||||||
JOIN topics t ON p.topic_id = t.id
|
JOIN topics t ON p.topic_id = t.id
|
||||||
WHERE pcf.name = 'is_accepted_answer'
|
WHERE p.user_id <> t.user_id -- ignore topics solved by OP
|
||||||
AND p.user_id <> t.user_id -- ignore topics solved by OP
|
AND (:backfill OR p.id IN (:post_ids))
|
||||||
AND (:backfill OR p.id IN (:post_ids))
|
|
||||||
) x
|
) x
|
||||||
WHERE row_number = 1
|
WHERE row_number = 1
|
||||||
SQL
|
SQL
|
||||||
|
@ -32,12 +31,11 @@ end
|
||||||
|
|
||||||
def solved_query_with_count(min_count)
|
def solved_query_with_count(min_count)
|
||||||
<<~SQL
|
<<~SQL
|
||||||
SELECT p.user_id, MAX(pcf.created_at) AS granted_at
|
SELECT p.user_id, MAX(dss.created_at) AS granted_at
|
||||||
FROM post_custom_fields pcf
|
FROM discourse_solved_solutions dss
|
||||||
JOIN badge_posts p ON pcf.post_id = p.id
|
JOIN badge_posts p ON dss.answer_post_id = p.id
|
||||||
JOIN topics t ON p.topic_id = t.id
|
JOIN topics t ON p.topic_id = t.id
|
||||||
WHERE pcf.name = 'is_accepted_answer'
|
WHERE p.user_id <> t.user_id -- ignore topics solved by OP
|
||||||
AND p.user_id <> t.user_id -- ignore topics solved by OP
|
|
||||||
AND (:backfill OR p.id IN (:post_ids))
|
AND (:backfill OR p.id IN (:post_ids))
|
||||||
GROUP BY p.user_id
|
GROUP BY p.user_id
|
||||||
HAVING COUNT(*) >= #{min_count}
|
HAVING COUNT(*) >= #{min_count}
|
||||||
|
|
Loading…
Reference in New Issue