diff --git a/backend/src/dal/leaderboards.ts b/backend/src/dal/leaderboards.ts index 81669f98c622..6f3c2af16a1d 100644 --- a/backend/src/dal/leaderboards.ts +++ b/backend/src/dal/leaderboards.ts @@ -13,19 +13,28 @@ export async function get( skip: number, limit = 50 ): Promise { - 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( - `leaderboards.${language}.${mode}.${mode2}` - ) - .find() - .sort({ rank: 1 }) - .skip(skip) - .limit(limit) - .toArray(); - return preset; + try { + const preset = await db + .collection( + `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 = {