diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2022-04-21 08:03:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-21 08:03:39 +0100 |
| commit | ed4e07d2e63af1584a262037781729a5144a5502 (patch) | |
| tree | 38bdb691cd060860e7a3fced7901c74283ddf2f1 /atuin-server/src/handlers/history.rs | |
| parent | Bump clap from 3.1.9 to 3.1.10 (#309) (diff) | |
| download | atuin-ed4e07d2e63af1584a262037781729a5144a5502.zip | |
Use the count cache (#312)
* Use the count cache
By default read from the count cache - if there is no value there, then
do a full COUNT. The cache will be filled when the user posts up some
more history
* clean up server db error handling
Co-authored-by: Conrad Ludgate <conrad.ludgate@truelayer.com>
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)), + }, } } |
