chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
A pull's checks are read from the index on its pull
crates/knotless-serve/src/index.rs+18−7
| @@ -738,7 +738,9 @@ const EXPRESSIONS: &str = | ||
CREATE INDEX IF NOT EXISTS forge_moderation ON forge (repo_did, repo_key) | ||
WHERE instr(uri, '/dev.knotless.block/') OR instr(uri, '/dev.knotless.hide/'); | ||
CREATE INDEX IF NOT EXISTS check_pull ON check_run (json_extract(value, '$.pull'), | ||
json_extract(value, '$.workflow'), started_at);"; | ||
json_extract(value, '$.workflow'), started_at); | ||
CREATE INDEX IF NOT EXISTS check_pull_at ON check_run (json_extract(value, '$.pull'), | ||
started_at, uri);"; | ||
| ||
/// Drops the tables that are a cache. Takedowns, the labels given out for | ||
/// them and reports are not, and stay; nor are pushes, since compaction | ||
| @@ -2625,19 +2627,28 @@ impl Index { | ||
.commits | ||
.map(|c| serde_json::to_string(c).unwrap_or_default()); | ||
let db = self.readers.take(&self.db); | ||
let mut stmt = db.prepare_cached( | ||
"SELECT uri, author, value, started_at FROM check_run | ||
WHERE repo_did = ?1 AND repo_key = ?2 | ||
// A pull's checks are read from its own, newest first, rather than | ||
// the repository's walked for the few that are its: `?9 IS NULL OR` | ||
// would keep the planner from the index on the pull. | ||
let pulled = match filter.pull { | ||
Some(_) => { | ||
"check_run INDEXED BY check_pull_at | ||
WHERE json_extract(value, '$.pull') = ?9 AND +repo_did = ?1" | ||
} | ||
None => "check_run WHERE repo_did = ?1 AND ?9 IS NULL", | ||
}; | ||
let mut stmt = db.prepare_cached(&format!( | ||
"SELECT uri, author, value, started_at FROM {pulled} | ||
AND repo_key = ?2 | ||
AND author IN (SELECT value FROM json_each(?3)) | ||
AND (?4 IS NULL OR ref = ?4) AND (?5 IS NULL OR sha = ?5) | ||
AND (?12 IS NULL OR sha IN (SELECT value FROM json_each(?12))) | ||
AND (?9 IS NULL OR json_extract(value, '$.pull') = ?9) | ||
AND (NOT ?10 OR json_array_length(value, '$.batch') > 0) | ||
AND (?11 IS NULL OR json_extract(value, '$.workflow') = ?11) | ||
AND (started_at < ?6 OR (started_at = ?6 AND uri < ?7)) | ||
AND uri NOT IN down AND author NOT IN down | ||
ORDER BY started_at DESC, uri DESC LIMIT ?8", | ||
)?; | ||
ORDER BY started_at DESC, uri DESC LIMIT ?8" | ||
))?; | ||
let rows: Vec<(Entry, String)> = stmt | ||
.query_map( | ||
params![ | ||