Skip to content

Commit 0ee5eeb

Browse files
committed
chore: return leaderboard for published maps in v4 api
1 parent 0946c00 commit 0ee5eeb

6 files changed

Lines changed: 93 additions & 50 deletions

File tree

api/v4Internal/model_maps.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ func hydratePublishedMap(m mapdb.PublishedMap) MapData {
236236
extra["boat"] = true
237237
}
238238

239+
leaderboard := defaultPlaytimeLeaderboard
240+
if m.Leaderboard != nil {
241+
leaderboard = Leaderboard{
242+
Asc: m.Leaderboard.Asc,
243+
Format: LeaderboardFormat(m.Leaderboard.Format),
244+
Score: m.Leaderboard.Score,
245+
}
246+
}
247+
239248
return MapData{
240249
ID: m.ID,
241250
Owner: m.Owner,
@@ -245,14 +254,15 @@ func hydratePublishedMap(m mapdb.PublishedMap) MapData {
245254

246255
Verification: hydrateMapVerification(m.Verification),
247256
Settings: MapSettings{
248-
Name: util.NilToEmpty(m.OptName), // todo should not be optional in db
249-
Icon: util.NilToEmpty(m.OptIcon), // todo should not be optional in db
250-
Size: hydrateMapSize(m.Size),
251-
Variant: hydrateMapVariant(m.OptVariant),
252-
Subvariant: m.OptSubvariant,
253-
Tags: m.OptTags,
254-
SpawnPoint: hydratePos(m.OptSpawnPoint),
255-
Extra: extra,
257+
Name: util.NilToEmpty(m.OptName), // todo should not be optional in db
258+
Icon: util.NilToEmpty(m.OptIcon), // todo should not be optional in db
259+
Size: hydrateMapSize(m.Size),
260+
Variant: hydrateMapVariant(m.OptVariant),
261+
Subvariant: m.OptSubvariant,
262+
Tags: m.OptTags,
263+
SpawnPoint: hydratePos(m.OptSpawnPoint),
264+
Leaderboard: &leaderboard,
265+
Extra: extra,
256266
},
257267

258268
PublishedId: m.PublishedID,

internal/mapdb/leaderboards.sql.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mapdb/maps.sql.go

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
begin;
2+
3+
drop view if exists maps_published;
4+
create or replace view maps_published as
5+
select m.*,
6+
array(select tag from map_tags where map_id = m.id order by index)::map_tag[] as tags,
7+
coalesce(stats.play_count, 0) as play_count,
8+
coalesce(stats.win_count, 0) as win_count,
9+
coalesce(stats.clear_rate::float, 0::float)::float as clear_rate,
10+
case
11+
when stats.play_count < 10 then -1
12+
when stats.clear_rate < 0.05 then 4
13+
when stats.clear_rate < 0.25 then 3
14+
when stats.clear_rate < 0.5 then 2
15+
when stats.clear_rate < 0.75 then 1
16+
else 0
17+
end as difficulty
18+
from maps as m
19+
left join (select map_id, play_count, win_count, win_count::float / nullif(play_count, 0)::float as clear_rate
20+
from map_stats) stats on m.id = stats.map_id
21+
where m.deleted_at is null
22+
and m.published_at is not null
23+
and m.published_id is not null;
24+
25+
commit;

internal/mapdb/models.go

Lines changed: 39 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mapdb/sqlc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ sql:
6060
go_type: { type: "MapExt" }
6161
- column: "maps.leaderboard"
6262
go_type: { type: "Leaderboard", pointer: true }
63+
- column: "maps_published.leaderboard"
64+
go_type: { type: "Leaderboard", pointer: true }
6365
- column: "maps_published.ext"
6466
go_type: { type: "MapExt" }
6567

0 commit comments

Comments
 (0)