Account for user not yet having count cache (#812)

* Account for user not yet having count cache

* Make clippy happy
This commit is contained in:
Ellie Huxtable 2023-03-26 17:48:41 +01:00 committed by GitHub
parent 954e20fd86
commit c30b457fc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

3
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,3 @@
# Contributing
Firstly, thank you so much for considering contributing to Atuin!

View file

@ -14,16 +14,22 @@ pub async fn status<DB: Database>(
) -> Result<Json<StatusResponse>, ErrorResponseStatus<'static>> { ) -> Result<Json<StatusResponse>, ErrorResponseStatus<'static>> {
let db = &state.0.database; let db = &state.0.database;
let history_count = db.count_history_cached(&user).await; let deleted = db.deleted_history(&user).await.unwrap_or(vec![]);
let deleted = db.deleted_history(&user).await;
if history_count.is_err() || deleted.is_err() { let count = match db.count_history_cached(&user).await {
return Err(ErrorResponse::reply("failed to query history count") // By default read out the cached value
.with_status(StatusCode::INTERNAL_SERVER_ERROR)); Ok(count) => count,
}
Ok(Json(StatusResponse { // If that fails, fallback on a full COUNT. Cache is built on a POST
count: history_count.unwrap(), // only
deleted: deleted.unwrap(), Err(_) => match db.count_history(&user).await {
})) Ok(count) => count,
Err(_) => {
return Err(ErrorResponse::reply("failed to query history count")
.with_status(StatusCode::INTERNAL_SERVER_ERROR))
}
},
};
Ok(Json(StatusResponse { count, deleted }))
} }