35
35
HashMap ,
36
36
HashSet ,
37
37
} ,
38
+ iter:: zip,
38
39
time:: Duration ,
39
40
} ,
40
41
tokio:: {
@@ -374,10 +375,9 @@ impl Poller {
374
375
let mapping_accounts = self
375
376
. fetch_mapping_accounts ( self . mapping_account_key )
376
377
. await ?;
377
- let product_accounts = self
378
- . fetch_product_accounts ( mapping_accounts. values ( ) )
378
+ let ( product_accounts, price_accounts ) = self
379
+ . fetch_product_and_price_accounts ( mapping_accounts. values ( ) )
379
380
. await ?;
380
- let price_accounts = self . fetch_price_accounts ( product_accounts. values ( ) ) . await ?;
381
381
382
382
Ok ( Data :: new (
383
383
mapping_accounts,
@@ -409,10 +409,13 @@ impl Poller {
409
409
Ok ( accounts)
410
410
}
411
411
412
- async fn fetch_product_accounts < ' a , A > (
412
+ async fn fetch_product_and_price_accounts < ' a , A > (
413
413
& self ,
414
414
mapping_accounts : A ,
415
- ) -> Result < HashMap < Pubkey , ProductAccount > >
415
+ ) -> Result < (
416
+ HashMap < Pubkey , ProductAccount > ,
417
+ HashMap < Pubkey , PriceAccount > ,
418
+ ) >
416
419
where
417
420
A : IntoIterator < Item = & ' a MappingAccount > ,
418
421
{
@@ -431,37 +434,32 @@ impl Poller {
431
434
}
432
435
}
433
436
434
- let product_accounts = join_all ( futures)
437
+ let future_results = join_all ( futures)
435
438
. await
436
439
. into_iter ( )
437
440
. collect :: < Result < Vec < _ > > > ( ) ?;
438
441
439
- Ok ( pubkeys
440
- . into_iter ( )
441
- . zip ( product_accounts. into_iter ( ) )
442
- . collect ( ) )
443
- }
444
-
445
- async fn fetch_price_accounts < ' a , P > (
446
- & self ,
447
- product_accounts : P ,
448
- ) -> Result < HashMap < Pubkey , PriceAccount > >
449
- where
450
- P : IntoIterator < Item = & ' a ProductAccount > ,
451
- {
452
- let mut price_accounts = HashMap :: new ( ) ;
442
+ let product_accounts = zip (
443
+ pubkeys. into_iter ( ) ,
444
+ future_results
445
+ . clone ( )
446
+ . into_iter ( )
447
+ . map ( |( product_account, _) | product_account) ,
448
+ )
449
+ . collect ( ) ;
453
450
454
- for product_account in product_accounts {
455
- for price_account_key in & product_account. price_accounts {
456
- let price_account = self . fetch_price_account ( price_account_key) . await ?;
457
- price_accounts. insert ( * price_account_key, price_account) ;
458
- }
459
- }
451
+ let price_accounts = future_results
452
+ . into_iter ( )
453
+ . flat_map ( |( _, price_accounts) | price_accounts. into_iter ( ) )
454
+ . collect ( ) ;
460
455
461
- Ok ( price_accounts)
456
+ Ok ( ( product_accounts , price_accounts) )
462
457
}
463
458
464
- async fn fetch_product_account ( & self , product_account_key : & Pubkey ) -> Result < ProductAccount > {
459
+ async fn fetch_product_account (
460
+ & self ,
461
+ product_account_key : & Pubkey ,
462
+ ) -> Result < ( ProductAccount , HashMap < Pubkey , PriceAccount > ) > {
465
463
// Fetch the product account
466
464
let product_account = * load_product_account (
467
465
& self
@@ -487,7 +485,7 @@ impl Poller {
487
485
price_accounts : price_accounts. keys ( ) . cloned ( ) . collect ( ) ,
488
486
} ;
489
487
490
- Ok ( product_account)
488
+ Ok ( ( product_account, price_accounts ) )
491
489
}
492
490
493
491
async fn fetch_price_account ( & self , price_account_key : & Pubkey ) -> Result < PriceAccount > {
0 commit comments