diff options
| author | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
| commit | 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch) | |
| tree | 7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/db/metrics.rs | |
| parent | 9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff) | |
| download | aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip | |
rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off
rustfmt.toml fixes the shape the tree is written in (120 columns, small
items kept on one line) and one canonical pass makes it the truth.
[lints.clippy] names the idiom lints worth enforcing and leaves out the
two that would add doc-comment boilerplate rather than remove it. The
tree pays them off here: write!/writeln! instead of push_str(&format!()),
let-else instead of match-on-Option, borrows where a thread entry point
only reads what it owns, no `&self` on a Copy state and no `self` nobody
reads.
ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and
value are now emitted by the same call instead of three.
Diffstat (limited to 'src/db/metrics.rs')
| -rw-r--r-- | src/db/metrics.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/db/metrics.rs b/src/db/metrics.rs index 39a6b10..6c4c519 100644 --- a/src/db/metrics.rs +++ b/src/db/metrics.rs @@ -1,6 +1,6 @@ use rusqlite::params; -use crate::db::*; +use crate::db::Db; use crate::error::{Error, Result}; use crate::time; @@ -8,10 +8,7 @@ use crate::time; fn count_rows(db: &Db, sql: &str) -> Result<i64> { let sql = sql.to_string(); - db.read(move |c| { - c.query_row(&sql, [], |r| r.get::<_, i64>(0)) - .map_err(|e| Error::db(e.to_string())) - }) + db.read(move |c| c.query_row(&sql, [], |r| r.get::<_, i64>(0)).map_err(|e| Error::db(e.to_string()))) } pub fn build_state_counts(db: &Db) -> Result<Vec<(String, i64)>> { @@ -45,7 +42,8 @@ pub fn count_pending_reviews(db: &Db) -> Result<i64> { pub fn pending_review_ages_secs(db: &Db, now: &str) -> Result<Vec<i64>> { db.read(|c| { - let mut st = c.prepare("SELECT julianday(?1) - julianday(detected_at) FROM candidate WHERE state='pending_review'")?; + let mut st = + c.prepare("SELECT julianday(?1) - julianday(detected_at) FROM candidate WHERE state='pending_review'")?; let rows = st.query_map(params![now], |r| r.get::<_, Option<f64>>(0))?; let mut out = Vec::new(); for r in rows { @@ -73,13 +71,9 @@ pub fn count_unacknowledged_notices(db: &Db) -> Result<i64> { pub fn artifact_bytes_served(db: &Db) -> Result<u64> { db.read(|c| { - c.query_row( - "SELECT COALESCE(sum(size),0) FROM artifact WHERE purged_at IS NULL", - [], - |r| r.get::<_, i64>(0), - ) - .map(|v| v.max(0) as u64) - .map_err(|e| Error::db(e.to_string())) + c.query_row("SELECT COALESCE(sum(size),0) FROM artifact WHERE purged_at IS NULL", [], |r| r.get::<_, i64>(0)) + .map(|v| v.max(0) as u64) + .map_err(|e| Error::db(e.to_string())) }) } @@ -98,4 +92,3 @@ pub fn last_poll_age_secs(db: &Db, now: &str) -> Result<Option<i64>> { })?; Ok(at.and_then(|t| time::delta_secs(now, &t))) } - |
