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

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/7953-cold-authenticated-home-still-reads-aske → main 1 commit fork

  • Merged. scout/7953-cold-authenticated-home-still-reads-aske was merged into main as f84ee16.

Review

Sign in to review this change.
3 files changed +43 −6
src/core/asked.ts +3 −1
@@ -172,7 +172,9 @@ export function pullsByAsk(
172172 issue.created_at, issue.parked, pull.merged_at,
173173 user.username AS author
174174 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%')
176178 ORDER BY issue.number`,
177179 )
178180 .all(...repoIds);
src/flow/vitals.ts +5 −5
@@ -70,12 +70,12 @@ export function readVitals(db: Database, now = new Date(), publicOnly = false):
7070 const row = db
7171 .query<Omit<Vitals, "conflicted" | "red" | "queued" | "oldestApprovedHours" | "strandedUsd" | "gateMinutes1h" | "pullCheckMinutes1h" | "batches6h" | "redBatchRate">, [string, string, string, number]>(
7272 `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
7474 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,
7979 (SELECT COUNT(*) FROM pull p JOIN issue i ON i.id = p.issue_id JOIN repo r ON r.id = i.repo_id
8080 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,
8181 (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 @@
55 */
66 import { afterAll, beforeAll, expect, test } from "bun:test";
77 import { breakerParked, WAITING_NOTES } from "../src/crew/breaker.ts";
8 import { pullsByAsk } from "../src/core/asked.ts";
89 import { readPipeline } from "../src/flow/pipeline.ts";
910 import { readVitals } from "../src/flow/vitals.ts";
1011 import { id } from "../src/kernel/id.ts";
@@ -95,3 +96,37 @@ test("ready asks: the tally is the old join's, counted by hand", () => {
9596 db.query("UPDATE repo SET autonomy = 'off'").run();
9697 expect(ready()).toBe(0);
9798 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs