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.
This commit is contained in:
Ellie Huxtable
2023-07-14 20:44:47 +01:00
committed by GitHub
parent 97e24d0d41
commit 5786155969
4 changed files with 27 additions and 2 deletions

View File

@ -100,6 +100,21 @@ impl Database for Postgres {
Ok(res.0)
}
#[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(