@@ -193,22 +193,20 @@ struct InfraListResponse {
193
193
#[ get( "" ) ]
194
194
async fn list (
195
195
db_pool : Data < DbConnectionPoolV2 > ,
196
- _core : Data < CoreClient > ,
197
196
pagination_params : Query < PaginationQueryParam > ,
198
197
) -> Result < Json < InfraListResponse > > {
199
198
let settings = pagination_params
200
199
. validate ( 1000 ) ?
201
200
. warn_page_size ( 100 )
202
201
. into_selection_settings ( ) ;
203
202
204
- let ( ( infras, stats) , infra_states ) = {
203
+ let ( infras, stats) = {
205
204
let conn = & mut db_pool. get ( ) . await ?;
206
- futures:: try_join!(
207
- Infra :: list_paginated( conn, settings) ,
208
- fetch_all_infra_states( db_pool. as_ref( ) ) ,
209
- ) ?
205
+ Infra :: list_paginated ( conn, settings) . await ?
210
206
} ;
211
207
208
+ let infra_states = fetch_all_infra_states ( & infras) . await ?;
209
+
212
210
let response = InfraListResponse {
213
211
stats,
214
212
results : infras
@@ -610,21 +608,18 @@ pub async fn fetch_infra_state(_infra_id: i64, _core: &CoreClient) -> Result<Inf
610
608
}
611
609
612
610
pub async fn fetch_all_infra_states (
613
- db_pool : & DbConnectionPoolV2 ,
611
+ infras : & [ Infra ] ,
614
612
) -> Result < HashMap < String , InfraStateResponse > > {
615
- let infras = Infra :: all ( db_pool. get ( ) . await ?. deref_mut ( ) )
616
- . await
617
- . into_iter ( )
618
- . map ( |infra| {
619
- (
620
- infra. id . to_string ( ) ,
621
- InfraStateResponse {
622
- // TODO: have a way to actually report infras states
623
- last_status : None ,
624
- status : InfraState :: Cached ,
625
- } ,
626
- )
627
- } ) ;
613
+ let infras = infras. iter ( ) . map ( |infra| {
614
+ (
615
+ infra. id . to_string ( ) ,
616
+ InfraStateResponse {
617
+ // TODO: have a way to actually report infras states
618
+ last_status : None ,
619
+ status : InfraState :: Cached ,
620
+ } ,
621
+ )
622
+ } ) ;
628
623
Ok ( HashMap :: from_iter ( infras) )
629
624
}
630
625
@@ -786,18 +781,7 @@ pub mod tests {
786
781
787
782
#[ rstest]
788
783
async fn infra_list ( ) {
789
- let db_pool = DbConnectionPoolV2 :: for_tests ( ) ;
790
- let mut core = MockingClient :: new ( ) ;
791
- core. stub ( "/cache_status" )
792
- . method ( reqwest:: Method :: POST )
793
- . response ( StatusCode :: OK )
794
- . body ( "{}" )
795
- . finish ( ) ;
796
-
797
- let app = TestAppBuilder :: new ( )
798
- . db_pool ( db_pool. clone ( ) )
799
- . core_client ( core. into ( ) )
800
- . build ( ) ;
784
+ let app = TestAppBuilder :: default_app ( ) ;
801
785
let request = TestRequest :: get ( ) . uri ( "/infra/" ) . to_request ( ) ;
802
786
803
787
app. fetch ( request) . assert_status ( StatusCode :: OK ) ;
0 commit comments