@@ -33,6 +33,7 @@ import { PoolService } from "src/endpoints/pool/pool.service";
33
33
import * as JsonDiff from "json-diff" ;
34
34
import { QueryPagination } from "src/common/entities/query.pagination" ;
35
35
import { StakeService } from "src/endpoints/stake/stake.service" ;
36
+ import { ApplicationMostUsed } from "src/endpoints/accounts/entities/application.most.used" ;
36
37
37
38
@Injectable ( )
38
39
export class CacheWarmerService {
@@ -377,21 +378,28 @@ export class CacheWarmerService {
377
378
async handleUpdateAccountTransfersLast24h ( ) {
378
379
const batchSize = 100 ;
379
380
const mostUsed = await this . accountService . getApplicationMostUsedRaw ( ) ;
381
+ const mostUsedIndexedAccounts = await this . indexerService . getAddressesWithTransfersLast24h ( ) ;
380
382
381
- const batches = BatchUtils . splitArrayIntoChunks ( mostUsed , batchSize ) ;
383
+ const allAddressesToUpdate = [ ...mostUsed . map ( item => item . address ) , ...mostUsedIndexedAccounts ] . distinct ( ) ;
384
+ const mostUsedDictionary = mostUsed . toRecord < ApplicationMostUsed > ( item => item . address ) ;
385
+
386
+ const batches = BatchUtils . splitArrayIntoChunks ( allAddressesToUpdate , batchSize ) ;
382
387
for ( const batch of batches ) {
383
388
const accounts = await this . indexerService . getAccounts (
384
389
new QueryPagination ( { from : 0 , size : batchSize } ) ,
385
- new AccountQueryOptions ( { addresses : batch . map ( item => item . address ) } ) ,
390
+ new AccountQueryOptions ( { addresses : batch } ) ,
391
+ [ 'address' , 'api_transfersLast24h' ] ,
386
392
) ;
387
393
388
- const accountsDictionary = accounts . toRecord < Account > ( account => account . address ) ;
394
+ const accountsDictionary = accounts . toRecord < Pick < Account , 'address' | 'api_transfersLast24h' > > ( account => account . address ) ;
395
+
396
+ for ( const address of batch ) {
397
+ const account = accountsDictionary [ address ] ;
398
+ const newTransfersLast24h = mostUsedDictionary [ address ] ?. transfers24H ?? 0 ;
389
399
390
- for ( const item of batch ) {
391
- const account = accountsDictionary [ item . address ] ;
392
- if ( account && account . api_transfersLast24h !== item . transfers24H ) {
393
- this . logger . log ( `Setting transferLast24h to ${ item . transfers24H } for account with address '${ item . address } '` ) ;
394
- await this . indexerService . setAccountTransfersLast24h ( item . address , item . transfers24H ) ;
400
+ if ( account && account . api_transfersLast24h !== newTransfersLast24h ) {
401
+ this . logger . log ( `Setting transferLast24h to ${ newTransfersLast24h } for account with address '${ address } '` ) ;
402
+ await this . indexerService . setAccountTransfersLast24h ( address , newTransfersLast24h ) ;
395
403
}
396
404
}
397
405
}
0 commit comments