From fdd004c50de6131be193044ae40424d691425a81 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 18:28:16 +0000 Subject: db, watch: two N+1s and a version rule with one owner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m-17. `watch::staleness::dependents_of` walked the index and asked for each package's recipe by name — one query per package, on the path that runs after every publish, with N equal to the size of the index. `db::index_recipes` returns the whole table in one query now. While there: a recipe that fails to parse is no longer treated as "does not depend on this package". An unreadable srcinfo used to hide a dependent from staleness by returning `None` into an `unwrap_or(false)`; now it is a reason to look. `db::builds::requeue_blocked` asked "is this name in the index?" once per dependency of every blocked build, inside the dispatcher's hot loop. The set of in-index names is read once per pass and tested in memory. Same answer, one query. m-18. `approved_but_unbuilt` assembled the version a human reads with two `CASE WHEN epoch='0'` expressions in SQL — a second, independent copy of the `epoch:pkgver-pkgrel` rule that `pkgver::full_version` owns. Two copies of a formatting rule is how the Attention page ends up describing versions differently from every other page. The query returns the parts; Rust formats them. A guard test fails if version-string concatenation reappears in SQL. --- src/db/builds.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/db/builds.rs') diff --git a/src/db/builds.rs b/src/db/builds.rs index 4244034..072836b 100644 --- a/src/db/builds.rs +++ b/src/db/builds.rs @@ -265,18 +265,20 @@ pub fn requeue_blocked(db: &Db) -> Result { .collect::>>()?; out }; + // The index membership check is one query for the whole pass, not one + // per dependency of every blocked build (m-17): the old shape was an N+1 + // whose N grew with the backlog, and it ran on the dispatcher's hot loop. + let in_index: std::collections::HashSet = { + let mut stmt = tx.prepare("SELECT name FROM package WHERE state='in_index'")?; + let names = stmt + .query_map([], |r| r.get::<_, String>(0))? + .collect::>>()?; + names.into_iter().collect() + }; let mut n = 0; for (id, blocked_on) in rows { let waiting: Vec = serde_json::from_str(&blocked_on).unwrap_or_default(); - let satisfied = waiting.iter().all(|name| { - tx.query_row( - "SELECT count(*) FROM package WHERE name=?1 AND state='in_index'", - params![name], - |r| r.get::<_, i64>(0), - ) - .unwrap_or(0) - > 0 - }); + let satisfied = waiting.iter().all(|name| in_index.contains(name)); if satisfied && !waiting.is_empty() { tx.execute( "UPDATE build SET state='queued', blocked_on_json='[]', updated_at=?1 WHERE id=?2", -- cgit v1.2.3