@@ -227,17 +227,17 @@ export const initStakePoolService = (props: StakePoolServiceProps): StakePoolPro
227
227
let cachedData : Promise < StakePoolCachedData > ;
228
228
let fetchingData = false ;
229
229
let healthStatus = false ;
230
- let index : Fuse < { id : Cardano . PoolId } > ;
230
+ let fuzzyIndex : Fuse < { id : Cardano . PoolId } > ;
231
231
232
- const createIndex = ( stakePools : Cardano . StakePool [ ] ) => {
232
+ const createFuzzyIndex = ( stakePools : Cardano . StakePool [ ] ) => {
233
233
const data = stakePools . map ( ( { id, metadata } ) => {
234
234
// metadata from BlockFrost API has more fields than required, extracting only the relevant ones to keep cache size small
235
235
const { description, homepage, name, ticker } = metadata || { } ;
236
236
237
237
return { description, homepage, id, name, ticker } ;
238
238
} ) ;
239
239
240
- index = new Fuse ( data , FUZZY_SEARCH_OPTIONS , Fuse . createIndex ( FUZZY_SEARCH_OPTIONS . keys , data ) ) ;
240
+ fuzzyIndex = new Fuse ( data , FUZZY_SEARCH_OPTIONS , Fuse . createIndex ( FUZZY_SEARCH_OPTIONS . keys , data ) ) ;
241
241
} ;
242
242
243
243
const saveData = ( data : StakePoolCachedData ) => {
@@ -296,7 +296,7 @@ export const initStakePoolService = (props: StakePoolServiceProps): StakePoolPro
296
296
stats : { qty : { activating : 0 , active, retired : 0 , retiring : retiringPools . length } }
297
297
} ;
298
298
299
- createIndex ( stakePools ) ;
299
+ createFuzzyIndex ( stakePools ) ;
300
300
saveData ( data ) ;
301
301
cachedData = Promise . resolve ( data ) ;
302
302
healthStatus = true ;
@@ -353,10 +353,10 @@ export const initStakePoolService = (props: StakePoolServiceProps): StakePoolPro
353
353
if ( pledgeMet ) result = result . filter ( ( pool ) => pool . pledge <= ( pool . metrics ?. stake . live || BigInt ( 0 ) ) ) ;
354
354
355
355
if ( text ) {
356
- const fuzzy = index . search ( text ) ;
356
+ const fuzzyResult = fuzzyIndex . search ( text ) ;
357
357
const idMap = new Map ( result . map ( ( pool ) => [ pool . id , pool ] ) ) ;
358
358
359
- result = fuzzy . map ( ( { item : { id } } ) => idMap . get ( id ) ) . filter ( Boolean ) as Cardano . StakePool [ ] ;
359
+ result = fuzzyResult . map ( ( { item : { id } } ) => idMap . get ( id ) ) . filter ( Boolean ) as Cardano . StakePool [ ] ;
360
360
}
361
361
362
362
if ( sort ) result . sort ( getSorter ( sort ) ) ;
@@ -378,8 +378,9 @@ export const initStakePoolService = (props: StakePoolServiceProps): StakePoolPro
378
378
// If the cache is present but expired, fetch the data in a fire and forget way.
379
379
if ( data . lastFetchTime < Date . now ( ) - ONE_DAY ) fetchData ( ) . catch ( console . error ) ;
380
380
381
- // Create the index to make the fuzzy search to work against cached data.
382
- createIndex ( data . stakePools ) ;
381
+ // If the cache is present, create the index to make the fuzzy search to work against cached data.
382
+ // The fuzzy index is an in memory Fuse object which can't be serialized and saved in the local storage with the cache.
383
+ createFuzzyIndex ( data . stakePools ) ;
383
384
}
384
385
385
386
healthStatus = true ;
0 commit comments