diff options
Diffstat (limited to 'src/db/builds.rs')
| -rw-r--r-- | src/db/builds.rs | 20 |
1 files changed, 11 insertions, 9 deletions
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<usize> { .collect::<rusqlite::Result<Vec<(String, String)>>>()?; 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<String> = { + let mut stmt = tx.prepare("SELECT name FROM package WHERE state='in_index'")?; + let names = stmt + .query_map([], |r| r.get::<_, String>(0))? + .collect::<rusqlite::Result<Vec<String>>>()?; + names.into_iter().collect() + }; let mut n = 0; for (id, blocked_on) in rows { let waiting: Vec<String> = 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", |
