@@ -5,8 +5,6 @@ import { setLeaderboard } from "../utils/prometheus";
55import { isDevEnvironment } from "../utils/misc" ;
66import { getCachedConfiguration } from "../init/configuration" ;
77
8- const leaderboardUpdating : Record < string , boolean > = { } ;
9-
108export async function get (
119 mode : string ,
1210 mode2 : string ,
@@ -57,21 +55,28 @@ export async function getRank(
5755 language : string ,
5856 uid : string
5957) : Promise < GetRankResponse | false > {
60- if ( leaderboardUpdating [ ` ${ language } _ ${ mode } _ ${ mode2 } ` ] ) return false ;
61- const entry = await db
62- . collection < SharedTypes . LeaderboardEntry > (
63- `leaderboards.${ language } .${ mode } .${ mode2 } `
64- )
65- . findOne ( { uid } ) ;
66- const count = await db
67- . collection ( `leaderboards.${ language } .${ mode } .${ mode2 } ` )
68- . estimatedDocumentCount ( ) ;
58+ try {
59+ const entry = await db
60+ . collection < SharedTypes . LeaderboardEntry > (
61+ `leaderboards.${ language } .${ mode } .${ mode2 } `
62+ )
63+ . findOne ( { uid } ) ;
64+ const count = await db
65+ . collection ( `leaderboards.${ language } .${ mode } .${ mode2 } ` )
66+ . estimatedDocumentCount ( ) ;
6967
70- return {
71- count,
72- rank : entry ? entry . rank : null ,
73- entry,
74- } ;
68+ return {
69+ count,
70+ rank : entry ? entry . rank : null ,
71+ entry,
72+ } ;
73+ } catch ( e ) {
74+ if ( e . error === 175 ) {
75+ //QueryPlanKilled, collection was removed during the query
76+ return false ;
77+ }
78+ throw e ;
79+ }
7580}
7681
7782export async function update (
@@ -84,7 +89,6 @@ export async function update(
8489} > {
8590 const key = `lbPersonalBests.${ mode } .${ mode2 } .${ language } ` ;
8691 const lbCollectionName = `leaderboards.${ language } .${ mode } .${ mode2 } ` ;
87- leaderboardUpdating [ `${ language } _${ mode } _${ mode2 } ` ] = true ;
8892 const lb = db
8993 . collection < MonkeyTypes . DBUser > ( "users" )
9094 . aggregate < SharedTypes . LeaderboardEntry > (
@@ -185,7 +189,6 @@ export async function update(
185189 const start2 = performance . now ( ) ;
186190 await db . collection ( lbCollectionName ) . createIndex ( { uid : - 1 } ) ;
187191 await db . collection ( lbCollectionName ) . createIndex ( { rank : 1 } ) ;
188- leaderboardUpdating [ `${ language } _${ mode } _${ mode2 } ` ] = false ;
189192 const end2 = performance . now ( ) ;
190193
191194 //update speedStats
0 commit comments