summaryrefslogtreecommitdiffstats
path: root/src/db/queries.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 17:09:59 +0000
committeraur-build <aur-build@localhost>2026-11-19 17:09:59 +0000
commite757979f1a2afdbe7146066345bb9acd19d3b151 (patch)
tree30d5f5fbccd25ea7bf01c5202684af463b74e7d3 /src/db/queries.rs
parent94c318f13264bb3c00a9f3057ba2e1aafb57c9e4 (diff)
downloadaur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.tar.gz
aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.zip
comments: say why, not what
Every module-level `//!` header is gone, and the comments that remained either re-explained the line below them or had grown into paragraphs. Density went from one comment line per 6.7 lines of code to one per 10. 827 insertions against 2194 deletions across 86 files. What survived: the invariants (I1-I12), the design cross-references into DESIGN.md, and the notes recording a bug that was found and fixed — those are the comments that carry weight, because they answer a question the code cannot answer about itself. What did not: restating a function signature in prose, and narration of the statement underneath.
Diffstat (limited to 'src/db/queries.rs')
-rw-r--r--src/db/queries.rs95
1 files changed, 33 insertions, 62 deletions
diff --git a/src/db/queries.rs b/src/db/queries.rs
index fe0518f..924051d 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -1,6 +1,3 @@
-//! Typed query helpers. Everything that mutates goes through the writer actor;
-//! everything that reads takes a `&Connection` from the reader pool.
-
use rusqlite::{params, params_from_iter, OptionalExtension, Row};
use crate::db::*;
@@ -12,9 +9,7 @@ use crate::time;
/// Every setting, for the settings page.
///
/// Row-error policy, applied everywhere in `db` (m-9): a row that cannot be read
-/// fails the query. `filter_map(|r| r.ok())` used to drop such rows silently,
-/// which is fine for a page that merely looks incomplete and fatal for the
-/// callers that decide what to reap, what to claim, and what is stale.
+/// fails the query rather than being dropped silently.
pub fn all_settings(db: &Db) -> Result<Vec<(String, String)>> {
db.read(|c| {
let mut st = c.prepare("SELECT key, value FROM settings ORDER BY key")?;
@@ -34,12 +29,10 @@ pub fn setting(db: &Db, key: &str) -> Result<Option<String>> {
/// An integer setting, or `default`.
///
/// The policy, stated once (m-9): a *missing* setting is normal — the default is
-/// the answer, and every knob in `settings` has one. A setting that is present
-/// but unparseable, or a read that failed outright, is not normal, and silently
-/// returning the default would hide an operator's typo behind a config that
-/// looks applied. Both still fall back — these are tuning knobs, and refusing to
-/// start over `stage_b_cooldown = 86400x` is worse than using the default — but
-/// they fall back out loud.
+/// the answer. A setting present but unparseable, or a read that failed, is not,
+/// and silently returning the default would hide an operator's typo. Both still
+/// fall back, because refusing to start over a tuning knob is worse — but they
+/// fall back out loud.
pub fn setting_i64(db: &Db, key: &str, default: i64) -> i64 {
match setting(db, key) {
Ok(None) => default,
@@ -101,14 +94,9 @@ pub fn audit(
})
}
-/// An audit row to append inside someone else's transaction.
-///
-/// Build one with [`AuditEntry::human`] or [`AuditEntry::system`] rather than
-/// by writing the literal: `actor_kind` is a closed set and the timestamp is
-/// not the caller's to improvise (§6 m-4). Three review sites had each
-/// hand-built this struct, and their `detail` shapes drifted until the log
-/// could not answer, for two of the three, which candidate bytes the decision
-/// was about.
+/// An audit row to append inside someone else's transaction. Build one with
+/// [`AuditEntry::human`] or [`AuditEntry::system`]: `actor_kind` is a closed set
+/// and the timestamp is not the caller's to improvise (§6 m-4).
#[derive(Debug)]
pub struct AuditEntry<'a> {
pub at: &'a str,
@@ -145,10 +133,8 @@ impl<'a> AuditEntry<'a> {
}
}
-/// Append an audit row inside a caller's transaction (I10). This is the variant
-/// every multi-statement mutation uses: the record of a decision commits with
-/// the decision or not at all, so there is no window where an audit row
-/// describes a change that was rolled back.
+/// Append an audit row inside a caller's transaction (I10), so the record of a
+/// decision commits with the decision or not at all.
pub fn audit_in(tx: &rusqlite::Transaction<'_>, e: &AuditEntry<'_>) -> Result<()> {
tx.execute(
"INSERT INTO audit (at, actor_kind, actor, action, entity, entity_id, detail_json)
@@ -523,16 +509,12 @@ const RELEASE_COLS_R: &str = "r.id, r.pkgbase_id, r.candidate_id, r.approval_id,
r.recipe_hash, r.upstream_pins_json, r.source_digests_json, r.epoch, r.pkgver, r.pkgrel, \
r.world_snapshot_id, r.state, r.published_at";
-/// Withdraw a published release and remove the packages it served (§9
-/// `repo-remove`, decision 23). Runs in the caller's transaction so the removal
-/// and the audit row that explains it are one fact.
-/// Take a release out of the served index (§9, decision 23).
+/// Take a release out of the served index (§9, decision 23), in the caller's
+/// transaction so the removal and the audit row explaining it are one fact.
///
/// Refuses a release that is not currently published (m-10): re-withdrawing used
-/// to report success and rewrite nothing, so an operator who clicked twice — or
-/// withdrew a release that had never been live — got a green result and no
-/// explanation. The write is a compare-and-swap on `state='published'`, and the
-/// refusal names the state that was actually there.
+/// to report success and rewrite nothing. The write is a compare-and-swap on
+/// `state='published'`, and the refusal names the state that was actually there.
pub fn withdraw_release_in(tx: &rusqlite::Transaction<'_>, release_id: i64) -> Result<()> {
let n = tx.execute(
"UPDATE release SET state='withdrawn' WHERE id=?1 AND state='published'",
@@ -679,10 +661,9 @@ pub fn index_version(db: &Db, name: &str) -> Result<Option<String>> {
})
}
-/// The exact artifact we serve for a package name: `(version, digest)` of the
-/// in-index row's artifact. This is what a build's lease manifest pins — the
-/// dependency arrives as these bytes or the build fails closed (§8,
-/// provisioning); nothing about it is re-resolved at build time.
+/// The exact artifact we serve for a package name: `(version, digest)`. This is
+/// what a build's lease manifest pins — the dependency arrives as these bytes or
+/// the build fails closed (§8).
pub fn index_artifact(db: &Db, name: &str) -> Result<Option<(String, String)>> {
db.read(|c| {
c.query_row(
@@ -766,9 +747,7 @@ pub fn builds_for_pkgbase(db: &Db, pkgbase_id: i64, limit: i64) -> Result<Vec<cr
// ------------------------------------------------------------ publish writes --
//
// Publishing is the one externally visible step, so every statement it needs is
-// here and the *decision* stays in `pipeline::publish`: the caller opens the
-// transaction, calls these in order, and bails if the compare-and-swap says the
-// world moved (I4).
+// here and the *decision* stays in `pipeline::publish` (I4).
/// The on-disk path of an artifact, by id.
pub fn artifact_path(db: &Db, id: i64) -> Result<Option<String>> {
@@ -899,9 +878,8 @@ pub fn insert_package_in(
// ------------------------------------------------------------ staleness reads --
//
-// Staleness is derived on read (§10.2), and these are the reads it is derived
-// from. They return plain tuples: the *meaning* ("this dependency moved") is
-// `watch::staleness`'s business, the SQL is this module's.
+// Staleness is derived on read (§10.2). These return plain tuples: the *meaning*
+// is `watch::staleness`'s business, the SQL is this module's.
/// `(pkgbase, world members JSON)` for every published release, taken from the
/// world snapshot its build recorded (§10.1).
@@ -944,13 +922,12 @@ pub fn served_vs_offered_pkgvers(db: &Db) -> Result<Vec<(String, String, String)
})
}
-/// The `srcinfo_json` of the recipe the index's copy of a package was built
-/// from — what its dependency list actually said.
-/// Every in-index package's recipe JSON, as (name, srcinfo_json).
+/// Every in-index package's recipe JSON, as (name, srcinfo_json) — what each
+/// dependency list actually said.
///
-/// One query, not one per package (m-17). `watch::staleness::dependents_of`
-/// wants the whole table: asking for each package by name was an N+1 whose N is
-/// the size of the index, on a code path that runs after every publish.
+/// One query, not one per package (m-17): `watch::staleness::dependents_of`
+/// wants the whole table, and asking per name was an N+1 on a path that runs
+/// after every publish.
pub fn index_recipes(db: &Db) -> Result<Vec<(String, String)>> {
db.read(|c| {
let mut stmt = c.prepare(
@@ -1314,10 +1291,7 @@ pub fn list_audit(db: &Db, limit: i64) -> Result<Vec<AuditRow>> {
// -------------------------------------------------------------- metrics reads --
//
-// The metrics surface is derived from live state, never stored (§10.3: a
-// counter that is written is a counter that can drift out of truth). These are
-// the reads that derivation is made of, and they live here because the schema
-// they read lives here.
+// The metrics surface is derived from live state, never stored (§10.3).
/// The `count(*)` idiom in one place, so a metric cannot accidentally become a
/// `count(*)` of a join.
@@ -1412,9 +1386,8 @@ pub fn last_gc_age_secs(db: &Db, now: &str) -> Result<Option<i64>> {
Ok(at.and_then(|t| time::delta_secs(now, &t)))
}
-/// Seconds since the last successful poll of any source, if there has been one.
-/// This is the metric that catches a watcher that stopped, which no log line
-/// will tell you about.
+/// Seconds since the last successful poll of any source. This is the metric that
+/// catches a watcher that stopped.
pub fn last_poll_age_secs(db: &Db, now: &str) -> Result<Option<i64>> {
let at = db.read(|c| {
c.query_row("SELECT max(last_checked_at) FROM subscription", [], |r| r.get::<_, Option<String>>(0))
@@ -1575,10 +1548,9 @@ pub fn index_pkgbase_drift(db: &Db) -> Result<(Vec<String>, Vec<String>)> {
})
}
-/// An approved change whose build failed and which therefore never reached the
-/// index (§8.4). This is the state that must never look healthy: a human said
-/// yes, the build died, and the index is quietly still serving the previous
-/// version. Surfacing it is the whole point of `approved_but_unbuilt`.
+/// An approved change whose build failed and never reached the index (§8.4). A
+/// human said yes, the build died, and the index is quietly still serving the
+/// previous version; surfacing that is the whole point.
#[derive(Debug, Clone)]
pub struct Unbuilt {
pub pkgbase: String,
@@ -1593,9 +1565,8 @@ pub struct Unbuilt {
pub fn approved_but_unbuilt(db: &Db) -> Result<Vec<Unbuilt>> {
db.read(|c| {
// The version strings are assembled in Rust by `pkgver::full_version`,
- // not by a CASE expression here (m-18): the epoch-omitted form is a rule
- // of ours, and a second copy of it in SQL is a second rule that can
- // disagree with the first.
+ // not by a CASE expression here (m-18): a second copy of the
+ // epoch-omission rule in SQL is a second rule that can disagree.
let mut stmt = c.prepare(
"SELECT p.name,
cnd.epoch, cnd.pkgver, cnd.pkgrel,