delay lock until it is needed

main
Zynh Ludwig 2024-08-30 23:08:32 -07:00
parent 7f62c9b6a8
commit 92d756741a
1 changed files with 1 additions and 1 deletions

View File

@ -21,7 +21,6 @@ async fn download(
State(state): State<AppState>, State(state): State<AppState>,
) -> Result<axum::response::Response, (StatusCode, String)> { ) -> Result<axum::response::Response, (StatusCode, String)> {
{ {
let mut records = state.records.lock().await;
if headers.get("hx-request").is_some() { if headers.get("hx-request").is_some() {
return Ok(axum::http::Response::builder() return Ok(axum::http::Response::builder()
.header("HX-Redirect", format!("/download/{id}")) .header("HX-Redirect", format!("/download/{id}"))
@ -31,6 +30,7 @@ async fn download(
.into_response()); .into_response());
} }
let mut records = state.records.lock().await;
if let Some(record) = records if let Some(record) = records
.get_mut(&id) .get_mut(&id)
.filter(|record| record.can_be_downloaded()) .filter(|record| record.can_be_downloaded())