diff options
Diffstat (limited to 'atuin-server/src/handlers/history.rs')
| -rw-r--r-- | atuin-server/src/handlers/history.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/atuin-server/src/handlers/history.rs b/atuin-server/src/handlers/history.rs index fde7cf2d..4fa2a962 100644 --- a/atuin-server/src/handlers/history.rs +++ b/atuin-server/src/handlers/history.rs @@ -13,10 +13,17 @@ pub async fn count( user: User, db: Extension<Postgres>, ) -> Result<Json<CountResponse>, ErrorResponseStatus<'static>> { - match db.count_history(&user).await { + match db.count_history_cached(&user).await { + // By default read out the cached value Ok(count) => Ok(Json(CountResponse { count })), - Err(_) => Err(ErrorResponse::reply("failed to query history count") - .with_status(StatusCode::INTERNAL_SERVER_ERROR)), + + // If that fails, fallback on a full COUNT. Cache is built on a POST + // only + Err(_) => match db.count_history(&user).await { + Ok(count) => Ok(Json(CountResponse { count })), + Err(_) => Err(ErrorResponse::reply("failed to query history count") + .with_status(StatusCode::INTERNAL_SERVER_ERROR)), + }, } } |
