From 578615596975b5a2e6aa8b8d7a8f36b9e390f9ea Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Fri, 14 Jul 2023 20:44:47 +0100 Subject: Add total history count to the index API (#1102) Thought it would be fun to collect some cool stats, maybe put them on atuin.sh. --- atuin-server-postgres/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'atuin-server-postgres/src') diff --git a/atuin-server-postgres/src/lib.rs b/atuin-server-postgres/src/lib.rs index 404188b0..fe1363ac 100644 --- a/atuin-server-postgres/src/lib.rs +++ b/atuin-server-postgres/src/lib.rs @@ -100,6 +100,21 @@ 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.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( -- cgit v1.3.1