From 126070068abda34fda0b880a36cc604b4ac8be2a Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Fri, 23 Jan 2026 12:27:43 -0800 Subject: chore!: remove total_history from api index response (#3094) Remove the expensive and inaccurate `total_history` field from the API index endpoint. The query `select sum(total) from total_history_count_user` ran on every request but is no longer relevant. The underlying table remains for per-user cached counts used by `/sync/count`. ## Checks - [x] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [x] I have checked that there are no existing pull requests for the same thing --- crates/atuin-common/src/api.rs | 1 - crates/atuin-server-database/src/lib.rs | 1 - crates/atuin-server-postgres/src/lib.rs | 15 --------------- crates/atuin-server-sqlite/src/lib.rs | 11 ----------- crates/atuin-server/src/handlers/mod.rs | 5 ----- 5 files changed, 33 deletions(-) (limited to 'crates') diff --git a/crates/atuin-common/src/api.rs b/crates/atuin-common/src/api.rs index 4e897811..1aaf9859 100644 --- a/crates/atuin-common/src/api.rs +++ b/crates/atuin-common/src/api.rs @@ -106,7 +106,6 @@ pub struct ErrorResponse<'a> { pub struct IndexResponse { pub homage: String, pub version: String, - pub total_history: i64, } #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/atuin-server-database/src/lib.rs b/crates/atuin-server-database/src/lib.rs index db170b50..a4ddf23c 100644 --- a/crates/atuin-server-database/src/lib.rs +++ b/crates/atuin-server-database/src/lib.rs @@ -113,7 +113,6 @@ pub trait Database: Sized + Clone + Send + Sync + 'static { async fn update_user_password(&self, u: &User) -> DbResult<()>; - async fn total_history(&self) -> DbResult; async fn count_history(&self, user: &User) -> DbResult; async fn count_history_cached(&self, user: &User) -> DbResult; diff --git a/crates/atuin-server-postgres/src/lib.rs b/crates/atuin-server-postgres/src/lib.rs index 8c40e6cc..54ba2ee8 100644 --- a/crates/atuin-server-postgres/src/lib.rs +++ b/crates/atuin-server-postgres/src/lib.rs @@ -244,21 +244,6 @@ impl Database for Postgres { Ok(res.0) } - #[instrument(skip_all)] - async fn total_history(&self) -> DbResult { - // The cache is new, and the user might not yet have a cache value. - // They will have one as soon as they post up some new history, but handle that - // edge case. - - let res: (i64,) = sqlx::query_as("select sum(total) from total_history_count_user") - .fetch_optional(self.read_pool()) - .await - .map_err(fix_error)? - .unwrap_or((0,)); - - Ok(res.0) - } - #[instrument(skip_all)] async fn count_history_cached(&self, user: &User) -> DbResult { let res: (i32,) = sqlx::query_as( diff --git a/crates/atuin-server-sqlite/src/lib.rs b/crates/atuin-server-sqlite/src/lib.rs index 9cc1e8a7..83d05ea5 100644 --- a/crates/atuin-server-sqlite/src/lib.rs +++ b/crates/atuin-server-sqlite/src/lib.rs @@ -231,17 +231,6 @@ impl Database for Sqlite { Ok(()) } - #[instrument(skip_all)] - async fn total_history(&self) -> DbResult { - let res: (i64,) = sqlx::query_as("select count(1) from history") - .fetch_optional(&self.pool) - .await - .map_err(fix_error)? - .unwrap_or((0,)); - - Ok(res.0) - } - #[instrument(skip_all)] async fn count_history(&self, user: &User) -> DbResult { // The cache is new, and the user might not yet have a cache value. diff --git a/crates/atuin-server/src/handlers/mod.rs b/crates/atuin-server/src/handlers/mod.rs index 1b9fd162..2176ac5e 100644 --- a/crates/atuin-server/src/handlers/mod.rs +++ b/crates/atuin-server/src/handlers/mod.rs @@ -16,10 +16,6 @@ const VERSION: &str = env!("CARGO_PKG_VERSION"); pub async fn index(state: State>) -> Json { let homage = r#""Through the fathomless deeps of space swims the star turtle Great A'Tuin, bearing on its back the four giant elephants who carry on their shoulders the mass of the Discworld." -- Sir Terry Pratchett"#; - // Error with a -1 response - // It's super unlikely this will happen - let count = state.database.total_history().await.unwrap_or(-1); - let version = state .settings .fake_version @@ -28,7 +24,6 @@ pub async fn index(state: State>) -> Json