File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -691,19 +691,25 @@ export class grpcDriftClientAccountSubscriberV2
691691 Array . from ( this . spotMarketsSubscriber ?. getAccountDataMap ( ) . values ( ) || [ ] )
692692 ) ;
693693
694- for ( const perpMarketIndex of perpMarketIndexes ) {
695- await this . perpMarketsSubscriber . removeAccounts ( [
696- new PublicKey (
697- this . perpMarketIndexToAccountPubkeyMap . get ( perpMarketIndex ) || ''
698- ) ,
699- ] ) ;
700- if ( this . delistedMarketSetting === DelistedMarketSetting . Discard ) {
701- this . perpMarketIndexToAccountPubkeyMap . delete ( perpMarketIndex ) ;
702- }
694+ // Build array of perp market pubkeys to remove
695+ const perpMarketPubkeysToRemove = perpMarketIndexes
696+ . map ( ( marketIndex ) => {
697+ const pubkeyString = this . perpMarketIndexToAccountPubkeyMap . get ( marketIndex ) ;
698+ return pubkeyString ? new PublicKey ( pubkeyString ) : null ;
699+ } )
700+ . filter ( ( pubkey ) => pubkey !== null ) as PublicKey [ ] ;
701+
702+ // Build array of oracle pubkeys to remove
703+ const oraclePubkeysToRemove = oracles . map ( ( oracle ) => oracle . publicKey ) ;
704+
705+ // Remove accounts in batches - perp markets
706+ if ( perpMarketPubkeysToRemove . length > 0 ) {
707+ await this . perpMarketsSubscriber . removeAccounts ( perpMarketPubkeysToRemove ) ;
703708 }
704709
705- for ( const oracle of oracles ) {
706- await this . oracleMultiSubscriber . removeAccounts ( [ oracle . publicKey ] ) ;
710+ // Remove accounts in batches - oracles
711+ if ( oraclePubkeysToRemove . length > 0 ) {
712+ await this . oracleMultiSubscriber . removeAccounts ( oraclePubkeysToRemove ) ;
707713 }
708714 }
709715
You can’t perform that action at this time.
0 commit comments