From 953dcbb7eb53836bb82ff70a452eab9611653d26 Mon Sep 17 00:00:00 2001 From: Younes Khoudli Date: Wed, 24 Jul 2024 07:06:15 +0200 Subject: [PATCH] editoast: fix list_infra hanging --- editoast/src/views/infra/mod.rs | 48 +++++++++++---------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index 2a84e85969d..c61245f25ca 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -193,7 +193,6 @@ struct InfraListResponse { #[get("")] async fn list( db_pool: Data, - _core: Data, pagination_params: Query, ) -> Result> { let settings = pagination_params @@ -201,14 +200,13 @@ async fn list( .warn_page_size(100) .into_selection_settings(); - let ((infras, stats), infra_states) = { + let (infras, stats) = { let conn = &mut db_pool.get().await?; - futures::try_join!( - Infra::list_paginated(conn, settings), - fetch_all_infra_states(db_pool.as_ref()), - )? + Infra::list_paginated(conn, settings).await? }; + let infra_states = fetch_all_infra_states(&infras).await?; + let response = InfraListResponse { stats, results: infras @@ -610,21 +608,18 @@ pub async fn fetch_infra_state(_infra_id: i64, _core: &CoreClient) -> Result Result> { - let infras = Infra::all(db_pool.get().await?.deref_mut()) - .await - .into_iter() - .map(|infra| { - ( - infra.id.to_string(), - InfraStateResponse { - // TODO: have a way to actually report infras states - last_status: None, - status: InfraState::Cached, - }, - ) - }); + let infras = infras.iter().map(|infra| { + ( + infra.id.to_string(), + InfraStateResponse { + // TODO: have a way to actually report infras states + last_status: None, + status: InfraState::Cached, + }, + ) + }); Ok(HashMap::from_iter(infras)) } @@ -786,18 +781,7 @@ pub mod tests { #[rstest] async fn infra_list() { - let db_pool = DbConnectionPoolV2::for_tests(); - let mut core = MockingClient::new(); - core.stub("/cache_status") - .method(reqwest::Method::POST) - .response(StatusCode::OK) - .body("{}") - .finish(); - - let app = TestAppBuilder::new() - .db_pool(db_pool.clone()) - .core_client(core.into()) - .build(); + let app = TestAppBuilder::default_app(); let request = TestRequest::get().uri("/infra/").to_request(); app.fetch(request).assert_status(StatusCode::OK);