aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-server-postgres
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-07-14 20:44:47 +0100
committerGitHub <noreply@github.com>2023-07-14 20:44:47 +0100
commit578615596975b5a2e6aa8b8d7a8f36b9e390f9ea (patch)
tree3898fe4b1b987ade80a3a8fb175bb09817bd7c5c /atuin-server-postgres
parentAdd new sync (#1093) (diff)
downloadatuin-578615596975b5a2e6aa8b8d7a8f36b9e390f9ea.zip
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.
Diffstat (limited to '')
-rw-r--r--atuin-server-postgres/src/lib.rs15
1 files changed, 15 insertions, 0 deletions
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
@@ -101,6 +101,21 @@ impl Database for Postgres {
}
#[instrument(skip_all)]
+ async fn total_history(&self) -> DbResult<i64> {
+ // 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<i64> {
let res: (i32,) = sqlx::query_as(
"select total from total_history_count_user