File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -276,7 +276,7 @@ export const MEMPOOL_PROCESS_DELAY = 100
276276// When fetching some address transactions, number of transactions to fetch at a time.
277277// On chronik, the max allowed is 200
278278export const CHRONIK_FETCH_N_TXS_PER_PAGE = 200
279- export const INITIAL_ADDRESS_SYNC_FETCH_CONCURRENTLY = 10
279+ export const INITIAL_ADDRESS_SYNC_FETCH_CONCURRENTLY = 5
280280export const TX_EMIT_BATCH_SIZE = 500
281281export const TRANSFORM_TX_FROM_CHRONIK_BATCH_SIZE = 10
282282export const DB_COMMIT_BATCH_SIZE = 500
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants'
3333import { AddressType } from 'ecashaddrjs/dist/types'
3434import { DecimalJsLike } from '@prisma/client/runtime/library'
3535
36+ const yieldEventLoop = async ( ) : Promise < void > => await new Promise ( resolve => setImmediate ( resolve ) )
3637const decoder = new TextDecoder ( )
3738
3839export function getNullDataScriptData ( outputScript : string ) : OpReturnData | null {
@@ -434,6 +435,9 @@ export class ChronikBlockchainClient {
434435
435436 syncedAlready += addressBatchSlice . length
436437
438+ // Yield event loop to prevent CPU starvation between address batches
439+ await yieldEventLoop ( )
440+
437441 // Yield full TX batches when buffer reaches TX_EMIT_BATCH_SIZE — use splice to drain in-place
438442 while ( chronikTxs . length >= TX_EMIT_BATCH_SIZE ) {
439443 const drained = chronikTxs . splice ( 0 , TX_EMIT_BATCH_SIZE )
@@ -865,6 +869,8 @@ export class ChronikBlockchainClient {
865869 } )
866870 )
867871 pairsFromBatch . push ( ...chunkResults )
872+ // Yield event loop between transform chunks to prevent CPU starvation
873+ await yieldEventLoop ( )
868874 }
869875
870876 for ( const { row } of pairsFromBatch ) {
You can’t perform that action at this time.
0 commit comments