@@ -335,10 +335,11 @@ void Indexes_SetTempSpecsTimers(TimerOp op) {
335335
336336//---------------------------------------------------------------------------------------------
337337
338- double IndexesScanner_IndexedPercent (IndexesScanner * scanner , IndexSpec * sp ) {
338+ double IndexesScanner_IndexedPercent (RedisModuleCtx * ctx , IndexesScanner * scanner , IndexSpec * sp ) {
339339 if (scanner || sp -> scan_in_progress ) {
340340 if (scanner ) {
341- return scanner -> totalKeys > 0 ? (double )scanner -> scannedKeys / scanner -> totalKeys : 0 ;
341+ size_t totalKeys = RedisModule_DbSize (ctx );
342+ return totalKeys > 0 ? (double )scanner -> scannedKeys / totalKeys : 0 ;
342343 } else {
343344 return 0 ;
344345 }
@@ -2111,7 +2112,6 @@ static IndexesScanner *IndexesScanner_NewGlobal() {
21112112 IndexesScanner * scanner = rm_calloc (1 , sizeof (IndexesScanner ));
21122113 scanner -> global = true;
21132114 scanner -> scannedKeys = 0 ;
2114- scanner -> totalKeys = RedisModule_DbSize (RSDummyContext );
21152115
21162116 global_spec_scanner = scanner ;
21172117 RedisModule_Log (RSDummyContext , "notice" , "Global scanner created" );
@@ -2122,7 +2122,6 @@ static IndexesScanner *IndexesScanner_NewGlobal() {
21222122static IndexesScanner * IndexesScanner_New (StrongRef global_ref ) {
21232123
21242124 IndexesScanner * scanner = rm_calloc (1 , sizeof (IndexesScanner ));
2125- scanner -> totalKeys = RedisModule_DbSize (RSDummyContext );
21262125
21272126 scanner -> spec_ref = StrongRef_Demote (global_ref );
21282127 IndexSpec * spec = StrongRef_Get (global_ref );
@@ -2420,7 +2419,7 @@ void IndexSpec_AddToInfo(RedisModuleInfoCtx *ctx, IndexSpec *sp) {
24202419 RedisModule_InfoAddFieldLongLong (ctx , "hash_indexing_failures" , sp -> stats .indexingFailures );
24212420 RedisModule_InfoAddFieldLongLong (ctx , "indexing" , !!global_spec_scanner || sp -> scan_in_progress );
24222421 IndexesScanner * scanner = global_spec_scanner ? global_spec_scanner : sp -> scanner ;
2423- double percent_indexed = IndexesScanner_IndexedPercent (scanner , sp );
2422+ double percent_indexed = IndexesScanner_IndexedPercent (ctx , scanner , sp );
24242423 RedisModule_InfoAddFieldDouble (ctx , "percent_indexed" , percent_indexed );
24252424 RedisModule_InfoEndDictField (ctx );
24262425
0 commit comments