Skip to content

Commit

Permalink
impr: provide all-time LB results during LB update (fehmer) (#5074)
Browse files Browse the repository at this point in the history
Try to provide LB results during the LB update. There is a very small time-frame where
already running queries might fail during the update. For now we keep the 503 error in this
cases and monitor how often this happens on production.
  • Loading branch information
fehmer committed Feb 19, 2024
1 parent d1b663a commit bf2c4cc
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions backend/src/dal/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ export async function get(
skip: number,
limit = 50
): Promise<SharedTypes.LeaderboardEntry[] | false> {
if (leaderboardUpdating[`${language}_${mode}_${mode2}`]) return false;
//if (leaderboardUpdating[`${language}_${mode}_${mode2}`]) return false;

if (limit > 50 || limit <= 0) limit = 50;
if (skip < 0) skip = 0;
const preset = await db
.collection<SharedTypes.LeaderboardEntry>(
`leaderboards.${language}.${mode}.${mode2}`
)
.find()
.sort({ rank: 1 })
.skip(skip)
.limit(limit)
.toArray();
return preset;
try {
const preset = await db
.collection<SharedTypes.LeaderboardEntry>(
`leaderboards.${language}.${mode}.${mode2}`
)
.find()
.sort({ rank: 1 })
.skip(skip)
.limit(limit)
.toArray();
return preset;
} catch (e) {
if (e.error === 175) {
//QueryPlanKilled, collection was removed during the query
return false;
}
throw e;
}
}

type GetRankResponse = {
Expand Down

0 comments on commit bf2c4cc

Please sign in to comment.