From bf2c4cc5bb7e9480fd44d8ef7b4fcd4a783a8a86 Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Mon, 19 Feb 2024 14:59:30 +0100 Subject: [PATCH] impr: provide all-time LB results during LB update (fehmer) (#5074) 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. --- backend/src/dal/leaderboards.ts | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) 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 = {