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>> {
let db = &state.0.database;
let history_count = db.count_history_cached(&user).await;
let deleted = db.deleted_history(&user).await;
let deleted = db.deleted_history(&user).await.unwrap_or(vec![]);
if history_count.is_err() || deleted.is_err() {
return Err(ErrorResponse::reply("failed to query history count")
.with_status(StatusCode::INTERNAL_SERVER_ERROR));
}
let count = match db.count_history_cached(&user).await {
// By default read out the cached value
Ok(count) => count,
Ok(Json(StatusResponse {
count: history_count.unwrap(),
deleted: deleted.unwrap(),
}))
// If that fails, fallback on a full COUNT. Cache is built on a POST
// only
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 }))
}