PuzzleTechHub / myus

A public hassle free puzzlehunt hosting tool
https://www.puzzlehuntmy.us/
MIT License
1 stars 9 forks source link

Leaderboard breaks on points update #21

Open TheOriginalSoni opened 7 months ago

TheOriginalSoni commented 7 months ago

Tried this in the actual DB

UPDATE myus_puzzle U2
SET points = 100
WHERE id=13;

This is supposed to mimic user changing points for one specific puzzle.

However, this breaks the leaderboard query.

SELECT "myus_team"."id", "myus_team"."name", "myus_team"."hunt_id", "myus_team"."creation_time", (SELECT SUM(U2."points") AS "score" FROM "myus_guess" U0 INNER JOIN "myus_puzzle" U2 ON (U0."puzzle_id" = U2."id") WHERE (U0."correct" AND U0."team_id" = ("myus_team"."id")) GROUP BY U2."points") AS "score", COUNT("myus_guess"."id") FILTER (WHERE "myus_guess"."correct") AS "solve_count", (SELECT U0."time" FROM "myus_guess" U0 WHERE (U0."correct" AND U0."team_id" = ("myus_team"."id")) ORDER BY U0."time" DESC LIMIT 1) AS "last_solve" FROM "myus_team" LEFT OUTER JOIN "myus_guess" ON ("myus_team"."id" = "myus_guess"."team_id") WHERE "myus_team"."hunt_id" = 3 GROUP BY "myus_team"."id" ORDER BY 5 DESC, 6 DESC, 7 ASC

and gives more than one row returned by a subquery used as an expression

Understand and fix leaderboard for future