Skip to content

Commit 953dcbb

Browse files
committed
editoast: fix list_infra hanging
1 parent daa3b7b commit 953dcbb

File tree

1 file changed

+16
-32
lines changed
  • editoast/src/views/infra

1 file changed

+16
-32
lines changed

editoast/src/views/infra/mod.rs

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,20 @@ struct InfraListResponse {
193193
#[get("")]
194194
async fn list(
195195
db_pool: Data<DbConnectionPoolV2>,
196-
_core: Data<CoreClient>,
197196
pagination_params: Query<PaginationQueryParam>,
198197
) -> Result<Json<InfraListResponse>> {
199198
let settings = pagination_params
200199
.validate(1000)?
201200
.warn_page_size(100)
202201
.into_selection_settings();
203202

204-
let ((infras, stats), infra_states) = {
203+
let (infras, stats) = {
205204
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?
210206
};
211207

208+
let infra_states = fetch_all_infra_states(&infras).await?;
209+
212210
let response = InfraListResponse {
213211
stats,
214212
results: infras
@@ -610,21 +608,18 @@ pub async fn fetch_infra_state(_infra_id: i64, _core: &CoreClient) -> Result<Inf
610608
}
611609

612610
pub async fn fetch_all_infra_states(
613-
db_pool: &DbConnectionPoolV2,
611+
infras: &[Infra],
614612
) -> 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+
});
628623
Ok(HashMap::from_iter(infras))
629624
}
630625

@@ -786,18 +781,7 @@ pub mod tests {
786781

787782
#[rstest]
788783
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();
801785
let request = TestRequest::get().uri("/infra/").to_request();
802786

803787
app.fetch(request).assert_status(StatusCode::OK);

0 commit comments

Comments
 (0)