@@ -22,22 +22,26 @@ where deleted is null
2222 and maps .published_at is not null ;
2323
2424-- name: GetTopTimesLeaderboard :many
25- select s1 . player_id ,
26- count (distinct s1 . map_id ) as top_times
27- from ( select map_id, min ((round( greatest(playtime, ticks * 20 ) / 50 .0 ) * 50 )::bigint ) as min_playtime
28- from save_states
25+ with
26+ shortest_playtimes as (
27+ select map_id, min ((greatest(round( playtime / 50 .0 ), ticks ) * 50 )::bigint ) as min_playtime
28+ from save_states
2929 join maps on save_states .map_id = maps .id
30- where deleted is null
31- and completed = true
32- and playtime != 0
33- and (type = ' playing' or type = ' verifying' )
34- and maps .published_at is not null
35- and maps .deleted_at is null
36- and coalesce(maps .leaderboard - >> ' format' , ' time' ) = ' time'
37- group by map_id) as shortest_playtimes
30+ where deleted is null
31+ and completed = true
32+ and playtime != 0
33+ and (type = ' playing' or type = ' verifying' )
34+ and maps .published_at is not null
35+ and maps .deleted_at is null
36+ and coalesce(maps .leaderboard - >> ' format' , ' time' ) = ' time'
37+ and coalesce(maps .leaderboard - >> ' asc' , ' true' ) = ' true'
38+ group by map_id
39+ )
40+ select s1 .player_id , count (distinct s1 .map_id ) as top_times
41+ from shortest_playtimes
3842 join save_states as s1
3943 on s1 .map_id = shortest_playtimes .map_id
40- and (round( greatest(s1 .playtime , s1 . ticks * 20 ) / 50 .0 ) * 50 )::bigint = shortest_playtimes .min_playtime
44+ and (greatest(round( s1 .playtime / 50 .0 ), s1 . ticks ) * 50 )::bigint = shortest_playtimes .min_playtime
4145where s1 .deleted is null
4246 and s1 .completed = true
4347group by s1 .player_id
0 commit comments