File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -68,12 +68,25 @@ export async function get(
6868 }
6969}
7070
71+ const cachedCounts = new Map < string , number > ( ) ;
72+
7173export async function getCount (
7274 mode : string ,
7375 mode2 : string ,
7476 language : string
7577) : Promise < number > {
76- return getCollection ( { language, mode, mode2 } ) . estimatedDocumentCount ( ) ;
78+ const key = `${ language } _${ mode } _${ mode2 } ` ;
79+ if ( cachedCounts . has ( key ) ) {
80+ return cachedCounts . get ( key ) as number ;
81+ } else {
82+ const count = await getCollection ( {
83+ language,
84+ mode,
85+ mode2,
86+ } ) . estimatedDocumentCount ( ) ;
87+ cachedCounts . set ( key , count ) ;
88+ return count ;
89+ }
7790}
7891
7992export async function getRank (
@@ -208,6 +221,8 @@ export async function update(
208221 await db . collection ( lbCollectionName ) . createIndex ( { rank : 1 } ) ;
209222 const end2 = performance . now ( ) ;
210223
224+ cachedCounts . delete ( `${ language } _${ mode } _${ mode2 } ` ) ;
225+
211226 //update speedStats
212227 const boundaries = [ ...Array ( 32 ) . keys ( ) ] . map ( ( it ) => it * 10 ) ;
213228 const statsKey = `${ language } _${ mode } _${ mode2 } ` ;
You can’t perform that action at this time.
0 commit comments