Skip to content

Commit a05c3d3

Browse files
committed
fix: global time leaderboard tick rounding being wrong
1 parent 232bfa3 commit a05c3d3

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

internal/mapdb/queries/leaderboards.sql

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,26 @@ order by top_times desc
4949
limit 10;
5050

5151
-- name: GetTopTimesLeaderboardForPlayer :one
52+
with
53+
shortest_playtimes as (
54+
select map_id, min((greatest(round(playtime / 50.0), ticks) * 50)::bigint) as min_playtime
55+
from save_states
56+
join maps on save_states.map_id = maps.id
57+
where deleted is null
58+
and completed = true
59+
and playtime != 0
60+
and (type = 'playing' or type = 'verifying')
61+
and maps.published_at is not null
62+
and maps.deleted_at is null
63+
and coalesce(maps.leaderboard ->> 'format', 'time') = 'time'
64+
and coalesce(maps.leaderboard ->> 'asc', 'true') = 'true'
65+
group by map_id
66+
)
5267
select count(distinct s1.map_id) as top_times
53-
from (select map_id, min((round(greatest(playtime, ticks * 20) / 50.0) * 50)::bigint) as min_playtime
54-
from save_states
55-
join maps on save_states.map_id = maps.id
56-
where deleted is null
57-
and completed = true
58-
and playtime != 0
59-
and (type = 'playing' or type = 'verifying')
60-
and maps.published_at is not null
61-
and maps.deleted_at is null
62-
and coalesce(maps.leaderboard ->> 'format', 'time') = 'time'
63-
group by map_id) as shortest_playtimes
68+
from shortest_playtimes
6469
join save_states as s1
6570
on s1.map_id = shortest_playtimes.map_id
66-
and (round(greatest(s1.playtime, s1.ticks * 20) / 50.0) * 50)::bigint = shortest_playtimes.min_playtime
71+
and (greatest(round(s1.playtime / 50.0), s1.ticks) * 50)::bigint = shortest_playtimes.min_playtime
6772
and s1.player_id = $1
6873
where s1.deleted is null
6974
and s1.completed = true;

0 commit comments

Comments
 (0)