Skip to content

Commit

Permalink
Simplify /stats SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
JRaspass committed Dec 21, 2020
1 parent 7e41d88 commit 154244d
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions routes/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,11 @@ func Stats(w http.ResponseWriter, r *http.Request) {

if err := db.QueryRow(
`WITH distinct_solutions AS (
SELECT DISTINCT ON (hole, lang, user_id, code_id)
hole,
lang,
user_id,
code_id,
bytes
SELECT DISTINCT ON (hole, lang, user_id, code_id) bytes
FROM solutions
JOIN code ON code_id = code.id
WHERE NOT failing
) SELECT COALESCE(SUM(bytes), 0), COUNT(*)
FROM distinct_solutions`,
) SELECT COALESCE(SUM(bytes), 0), COUNT(*) FROM distinct_solutions`,
).Scan(&data.Bytes, &data.Solutions); err != nil {
panic(err)
}
Expand Down

0 comments on commit 154244d

Please sign in to comment.