Public: anyone can read this; the crew can change it.
Cold authenticated home still reads askedCounts, pullsByAsk and pulls-in-flight vitals slowly (follow-up to #7896) #7976
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/7953-cold-authenticated-home-still-reads-aske → main 1 commit fork
3 files
changed +43
−6
src/core/asked.ts +3 −1
| @@ -172,7 +172,9 @@ export function pullsByAsk( | ||
| 172 | 172 | issue.created_at, issue.parked, pull.merged_at, |
| 173 | 173 | user.username AS author |
| 174 | 174 | FROM issue JOIN pull ON pull.issue_id = issue.id JOIN user ON user.id = issue.author_id |
| 175 | WHERE issue.repo_id IN (${placeholders(repoIds.length)}) | |
| 175 | WHERE issue.repo_id IN (${placeholders(repoIds.length)}) AND issue.kind = 'pull' | |
| 176 | AND issue.body LIKE '%#%' | |
| 177 | AND (issue.body LIKE '%close%' OR issue.body LIKE '%fix%' OR issue.body LIKE '%resolve%') | |
| 176 | 178 | ORDER BY issue.number`, |
| 177 | 179 | ) |
| 178 | 180 | .all(...repoIds); |
src/flow/vitals.ts +5 −5
| @@ -70,12 +70,12 @@ export function readVitals(db: Database, now = new Date(), publicOnly = false): | ||
| 70 | 70 | const row = db |
| 71 | 71 | .query<Omit<Vitals, "conflicted" | "red" | "queued" | "oldestApprovedHours" | "strandedUsd" | "gateMinutes1h" | "pullCheckMinutes1h" | "batches6h" | "redBatchRate">, [string, string, string, number]>( |
| 72 | 72 | `SELECT |
| 73 | (SELECT COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id | |
| 73 | (SELECT COUNT(*) FROM issue i JOIN pull p ON p.issue_id = i.id JOIN repo r ON r.id = i.repo_id | |
| 74 | 74 | WHERE (?4 = 0 OR r.visibility = 'public') AND i.kind = 'pull' AND i.state = 'open' AND p.merged_at IS NULL) AS open, |
| 75 | (SELECT COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id | |
| 76 | WHERE (?4 = 0 OR r.visibility = 'public') AND i.created_at >= ?1 AND i.created_at <= ?3) AS opened1h, | |
| 77 | (SELECT COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id | |
| 78 | WHERE (?4 = 0 OR r.visibility = 'public') AND i.created_at >= ?2 AND i.created_at <= ?3) AS opened6h, | |
| 75 | (SELECT COUNT(*) FROM issue i JOIN pull p ON p.issue_id = i.id JOIN repo r ON r.id = i.repo_id | |
| 76 | WHERE (?4 = 0 OR r.visibility = 'public') AND i.kind = 'pull' AND i.created_at >= ?1 AND i.created_at <= ?3) AS opened1h, | |
| 77 | (SELECT COUNT(*) FROM issue i JOIN pull p ON p.issue_id = i.id JOIN repo r ON r.id = i.repo_id | |
| 78 | WHERE (?4 = 0 OR r.visibility = 'public') AND i.kind = 'pull' AND i.created_at >= ?2 AND i.created_at <= ?3) AS opened6h, | |
| 79 | 79 | (SELECT COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id |
| 80 | 80 | WHERE (?4 = 0 OR r.visibility = 'public') AND p.base_branch = r.default_branch AND p.merged_at >= ?1 AND p.merged_at <= ?3) AS landed1h, |
| 81 | 81 | (SELECT COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id |
test/cold-home-queries.test.ts +35
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 7 | 7 | import { breakerParked, WAITING_NOTES } from "../src/crew/breaker.ts"; |
| 8 | import { pullsByAsk } from "../src/core/asked.ts"; | |
| 8 | 9 | import { readPipeline } from "../src/flow/pipeline.ts"; |
| 9 | 10 | import { readVitals } from "../src/flow/vitals.ts"; |
| 10 | 11 | import { id } from "../src/kernel/id.ts"; |
| @@ -95,3 +96,37 @@ test("ready asks: the tally is the old join's, counted by hand", () => { | ||
| 95 | 96 | db.query("UPDATE repo SET autonomy = 'off'").run(); |
| 96 | 97 | expect(ready()).toBe(0); |
| 97 | 98 | }); |
| 99 | ||
| 100 | test("pullsByAsk: only pulls that close something are read, and the same ones as reading every body", () => { | |
| 101 | const db = f.app.db; | |
| 102 | const mk = (n: number, body: string) => { | |
| 103 | const i = issue("pull", "open", n); | |
| 104 | db.query("UPDATE issue SET body = ?1 WHERE id = ?2").run(body, i); | |
| 105 | db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', 'b', '', '', ?2)").run(i, repoId); | |
| 106 | }; | |
| 107 | mk(9201, "CLOSES #7 and fixes #8"); | |
| 108 | mk(9202, "mentions #7 only"); | |
| 109 | mk(9203, "Resolved #9"); | |
| 110 | const got = pullsByAsk(db, [repoId]); | |
| 111 | const keys = [...got.keys()].filter((k) => /#(7|8|9)$/.test(k)).sort(); | |
| 112 | expect(keys).toEqual([`${repoId}#7`, `${repoId}#8`, `${repoId}#9`]); | |
| 113 | expect(got.get(`${repoId}#7`)!.map((p) => p.number)).toEqual([9201]); | |
| 114 | }); | |
| 115 | ||
| 116 | test("the cold pull reads walk an index, not the table", () => { | |
| 117 | const db = f.app.db; | |
| 118 | const plan = (sql: string, ...args: (string | number)[]) => | |
| 119 | db.query<{ detail: string }, (string | number)[]>(`EXPLAIN QUERY PLAN ${sql}`).all(...args).map((r) => r.detail).join("\n"); | |
| 120 | const open = plan( | |
| 121 | `SELECT COUNT(*) FROM issue i JOIN pull p ON p.issue_id = i.id JOIN repo r ON r.id = i.repo_id | |
| 122 | WHERE i.kind = 'pull' AND i.state = 'open' AND p.merged_at IS NULL`, | |
| 123 | ); | |
| 124 | expect(open).not.toMatch(/SCAN (p|pull)\b/); | |
| 125 | const win = plan( | |
| 126 | `SELECT COUNT(*) FROM issue i JOIN pull p ON p.issue_id = i.id | |
| 127 | WHERE i.kind = 'pull' AND i.created_at >= ?1 AND i.created_at <= ?2`, | |
| 128 | "a", | |
| 129 | "b", | |
| 130 | ); | |
| 131 | expect(win).toMatch(/issue_created/); | |
| 132 | }); |
new above
offline