10
10
Context ,
11
11
Result ,
12
12
} ,
13
+ futures_util:: future:: join_all,
13
14
pyth_sdk_solana:: state:: {
14
15
load_mapping_account,
15
16
load_price_account,
@@ -415,16 +416,30 @@ impl Poller {
415
416
where
416
417
A : IntoIterator < Item = & ' a MappingAccount > ,
417
418
{
418
- let mut product_accounts = HashMap :: new ( ) ;
419
+ let mut pubkeys = vec ! [ ] ;
420
+ let mut futures = vec ! [ ] ;
419
421
422
+ // Fetch all product accounts in parallel
420
423
for mapping_account in mapping_accounts {
421
- product_accounts. extend (
422
- self . fetch_product_accounts_from_mapping_account ( mapping_account)
423
- . await ?,
424
- ) ;
424
+ for account_key in mapping_account
425
+ . products
426
+ . iter ( )
427
+ . filter ( |pubkey| * * pubkey != Pubkey :: default ( ) )
428
+ {
429
+ pubkeys. push ( account_key. clone ( ) ) ;
430
+ futures. push ( self . fetch_product_account ( account_key) ) ;
431
+ }
425
432
}
426
433
427
- Ok ( product_accounts)
434
+ let product_accounts = join_all ( futures)
435
+ . await
436
+ . into_iter ( )
437
+ . collect :: < Result < Vec < _ > > > ( ) ?;
438
+
439
+ Ok ( pubkeys
440
+ . into_iter ( )
441
+ . zip ( product_accounts. into_iter ( ) )
442
+ . collect ( ) )
428
443
}
429
444
430
445
async fn fetch_price_accounts < ' a , P > (
@@ -446,24 +461,6 @@ impl Poller {
446
461
Ok ( price_accounts)
447
462
}
448
463
449
- async fn fetch_product_accounts_from_mapping_account (
450
- & self ,
451
- mapping_account : & MappingAccount ,
452
- ) -> Result < HashMap < Pubkey , ProductAccount > > {
453
- let mut product_accounts = HashMap :: new ( ) ;
454
- for account_key in mapping_account
455
- . products
456
- . iter ( )
457
- . filter ( |pubkey| * * pubkey != Pubkey :: default ( ) )
458
- {
459
- // Update the price accounts
460
- let product_account = self . fetch_product_account ( account_key) . await ?;
461
- product_accounts. insert ( * account_key, product_account) ;
462
- }
463
-
464
- Ok ( product_accounts)
465
- }
466
-
467
464
async fn fetch_product_account ( & self , product_account_key : & Pubkey ) -> Result < ProductAccount > {
468
465
// Fetch the product account
469
466
let product_account = * load_product_account (
0 commit comments