From e757979f1a2afdbe7146066345bb9acd19d3b151 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 17:09:59 +0000 Subject: comments: say why, not what MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/db/queries.rs | 95 +++++++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 62 deletions(-) (limited to 'src/db/queries.rs') 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> { 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> { /// 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> { }) } -/// 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> { db.read(|c| { c.query_row( @@ -766,9 +747,7 @@ pub fn builds_for_pkgbase(db: &Db, pkgbase_id: i64, limit: i64) -> Result Result> { @@ -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 Result> { db.read(|c| { let mut stmt = c.prepare( @@ -1314,10 +1291,7 @@ pub fn list_audit(db: &Db, limit: i64) -> Result> { // -------------------------------------------------------------- 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> { 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> { let at = db.read(|c| { c.query_row("SELECT max(last_checked_at) FROM subscription", [], |r| r.get::<_, Option>(0)) @@ -1575,10 +1548,9 @@ pub fn index_pkgbase_drift(db: &Db) -> Result<(Vec, Vec)> { }) } -/// 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> { 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, -- cgit v1.2.3