Skip to content

Commit

Permalink
declare showing ranking status
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Jun 3, 2024
1 parent 855d658 commit 849f199
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/server/backend/bancho.py/server/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { Mode, Rank, Ruleset } from '~/def'
import { UserProvider as Base, type MailTokenProvider } from '$base/server'
import type { ExtractLocationSettings, ExtractSettingType } from '$base/@define-setting'
import { type RankingSystemScore } from '~/def/score'
import { RankingStatus } from '~/def/beatmap'

type ServerSetting = ExtractSettingType<ExtractLocationSettings<DynamicSettingStore.Server, typeof settings>>

Expand Down Expand Up @@ -107,6 +108,9 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
},
]

protected readonly bestsRankingStatuses = [RankingStatus.Ranked, RankingStatus.Approved]
protected readonly topsRankingStatuses = [RankingStatus.Ranked, RankingStatus.Approved, RankingStatus.Qualified]

constructor() {
super()

Expand Down Expand Up @@ -232,7 +236,7 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
rankingSystem,
page,
perPage,
rankingStatus,
rankingStatus = this.bestsRankingStatuses,
}: Base.BaseQuery<Id, M, ActiveRuleset, RS>): Promise<RankingSystemScore<ScoreId, Id, Mode, RS>[]> {
const start = page * perPage
const _mode = toBanchoPyMode(mode, ruleset)
Expand Down Expand Up @@ -263,7 +267,7 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
? desc(score.pp)
: (rankingSystem === Rank.RankedScore || rankingSystem === Rank.TotalScore)
? desc(score.score)
: raiseError('unknown ranking system˝')
: raiseError('unknown ranking system')
)
.offset(start)
.limit(perPage)
Expand All @@ -280,11 +284,19 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
}

async getTops<M extends ActiveMode, RS extends LeaderboardRankingSystem>(opt: Base.BaseQuery<Id, M, ActiveRuleset, RS>) {
const { id, mode, ruleset, rankingSystem, page, perPage, rankingStatus } = opt
const {
id,
mode,
ruleset,
rankingSystem,
page,
perPage,
rankingStatus = this.topsRankingStatuses,
} = opt

const start = page * perPage

const banchoPyRankingStatus = rankingStatus.map(i => fromRankingStatus(i))
const banchoPyRankingStatus = rankingStatus?.map(i => fromRankingStatus(i))

// derived tables
const s = aliasedTable(schema.scores, 's')
Expand Down Expand Up @@ -459,7 +471,7 @@ class DBUserProvider extends Base<Id, ScoreId> implements Base<Id, ScoreId> {
returnValue.preferredMode = {
mode, ruleset,
}
const parallels: PromiseLike<any>[] = []
const parallels: Promise<any>[] = []

returnValue.status = UserStatus.Offline

Expand Down
11 changes: 11 additions & 0 deletions src/server/backend/[email protected]/server/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Scope, type UserCompact, UserRole, UserStatus } from '~/def/user'
import { ArticleProvider, UserProvider as BanchoPyUser } from '~/server/backend/bancho.py/server'
import { fromBanchoPyMode, toFullUser, toUserClan } from '~/server/backend/bancho.py/transforms'
import type { UserProvider as Base } from '$base/server'
import { RankingStatus } from '~/def/beatmap'

const logger = Logger.child({ label: 'user' })

Expand All @@ -34,6 +35,16 @@ export class UserProvider extends BanchoPyUser implements Base<Id, ScoreId> {
},
]

protected override readonly topsRankingStatuses = [
RankingStatus.Approved,
RankingStatus.Loved,
RankingStatus.Qualified,
RankingStatus.Ranked,
RankingStatus.WIP,
RankingStatus.Graveyard,
RankingStatus.Pending,
]

async changeSettings(
user: { id: Id; roles: UserRole[] },
input: {
Expand Down

0 comments on commit 849f199

Please sign in to comment.