Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr: provide all-time LB results during LB update (@fehmer) #5614

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions backend/src/dal/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { setLeaderboard } from "../utils/prometheus";
import { isDevEnvironment } from "../utils/misc";
import { getCachedConfiguration } from "../init/configuration";

const leaderboardUpdating: Record<string, boolean> = {};

export async function get(
mode: string,
mode2: string,
Expand Down Expand Up @@ -57,21 +55,28 @@ export async function getRank(
language: string,
uid: string
): Promise<GetRankResponse | false> {
if (leaderboardUpdating[`${language}_${mode}_${mode2}`]) return false;
const entry = await db
.collection<SharedTypes.LeaderboardEntry>(
`leaderboards.${language}.${mode}.${mode2}`
)
.findOne({ uid });
const count = await db
.collection(`leaderboards.${language}.${mode}.${mode2}`)
.estimatedDocumentCount();
try {
const entry = await db
.collection<SharedTypes.LeaderboardEntry>(
`leaderboards.${language}.${mode}.${mode2}`
)
.findOne({ uid });
const count = await db
.collection(`leaderboards.${language}.${mode}.${mode2}`)
.estimatedDocumentCount();

return {
count,
rank: entry ? entry.rank : null,
entry,
};
return {
count,
rank: entry ? entry.rank : null,
entry,
};
} catch (e) {
if (e.error === 175) {
//QueryPlanKilled, collection was removed during the query
return false;
}
throw e;
}
}

export async function update(
Expand All @@ -84,7 +89,6 @@ export async function update(
}> {
const key = `lbPersonalBests.${mode}.${mode2}.${language}`;
const lbCollectionName = `leaderboards.${language}.${mode}.${mode2}`;
leaderboardUpdating[`${language}_${mode}_${mode2}`] = true;
const lb = db
.collection<MonkeyTypes.DBUser>("users")
.aggregate<SharedTypes.LeaderboardEntry>(
Expand Down Expand Up @@ -185,7 +189,6 @@ export async function update(
const start2 = performance.now();
await db.collection(lbCollectionName).createIndex({ uid: -1 });
await db.collection(lbCollectionName).createIndex({ rank: 1 });
leaderboardUpdating[`${language}_${mode}_${mode2}`] = false;
const end2 = performance.now();

//update speedStats
Expand Down
Loading