@@ -691,19 +691,28 @@ 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 =
698+ this . perpMarketIndexToAccountPubkeyMap . get ( marketIndex ) ;
699+ return pubkeyString ? new PublicKey ( pubkeyString ) : null ;
700+ } )
701+ . filter ( ( pubkey ) => pubkey !== null ) as PublicKey [ ] ;
702+
703+ // Build array of oracle pubkeys to remove
704+ const oraclePubkeysToRemove = oracles . map ( ( oracle ) => oracle . publicKey ) ;
705+
706+ // Remove accounts in batches - perp markets
707+ if ( perpMarketPubkeysToRemove . length > 0 ) {
708+ await this . perpMarketsSubscriber . removeAccounts (
709+ perpMarketPubkeysToRemove
710+ ) ;
703711 }
704712
705- for ( const oracle of oracles ) {
706- await this . oracleMultiSubscriber . removeAccounts ( [ oracle . publicKey ] ) ;
713+ // Remove accounts in batches - oracles
714+ if ( oraclePubkeysToRemove . length > 0 ) {
715+ await this . oracleMultiSubscriber . removeAccounts ( oraclePubkeysToRemove ) ;
707716 }
708717 }
709718
0 commit comments