Public: anyone can read this; the crew can change it.
Group the home's per-app reads (Later gate, per-repo issue counts) so a cold / is fast #12311
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12310-group-the-home-s-per-app-reads-later-gat → main 5 commits fork
5 files
changed +46
−12
src/core/next_up.ts +4 −2
| @@ -131,7 +131,9 @@ export function nextUp( | ||
| 131 | 131 | /** Why a ready issue is not startable, by issue id (`crew/not_startable.ts`): a page that has the app passes it. */ |
| 132 | 132 | notStartable: (ready: readonly Ranked[]) => ReadonlyMap<string, string> = () => new Map(), |
| 133 | 133 | ): NextUp { |
| 134 | const graph = repoGraph(db, repo.id, { ...scope, lean: true }); | |
| 134 | // Read once: the graph and the pillar each row serves both want the repository's pillars. | |
| 135 | const set = pillarsOf(db, repo); | |
| 136 | const graph = repoGraph(db, repo.id, { ...scope, lean: true, pillars: set }); | |
| 135 | 137 | const ranks = graph.ranked ?? new Map<string, number>(); |
| 136 | 138 | const readyRanked = readyNow(graph); |
| 137 | 139 | const ready = readyRanked.map((r) => r.issue); |
| @@ -144,7 +146,7 @@ export function nextUp( | ||
| 144 | 146 | if (run.issueId !== null && who !== undefined) crew.set(run.issueId, who); |
| 145 | 147 | } |
| 146 | 148 | const holds = reachOf(graph).holds; |
| 147 | const serves = servedBy(db, pillarsOf(db, repo)); | |
| 149 | const serves = servedBy(db, set); | |
| 148 | 150 | const rowOf = (issue: Issue): NextRow => { |
| 149 | 151 | const why = readyIds.has(issue.id) ? unstartable.get(issue.id) ?? null : whyNot(graph, issue); |
| 150 | 152 | // Blocked is a fact of the graph (open work in front of it), not a reading of `why`. |
src/core/pillars.ts +25 −2
| @@ -456,6 +456,30 @@ function firstLiveOf( | ||
| 456 | 456 | export function reposWithUmbrellas( |
| 457 | 457 | db: Database, |
| 458 | 458 | repoIds: readonly string[], |
| 459 | ): Set<string> { | |
| 460 | return reposTitled(db, repoIds, "(title GLOB 'P[0-9]*' OR title LIKE 'Later%')"); | |
| 461 | } | |
| 462 | ||
| 463 | /** | |
| 464 | * Of these repositories, the ones with an open issue titled like the Later | |
| 465 | * gate: one read. A repository without one holds nothing back, so a surface | |
| 466 | * that reads each gate (`pillarsOf`) reads only these. | |
| 467 | */ | |
| 468 | export function reposWithGateTitle( | |
| 469 | db: Database, | |
| 470 | repoIds: readonly string[], | |
| 471 | ): Set<string> { | |
| 472 | return reposTitled(db, repoIds, "title LIKE 'Later gate:%'"); | |
| 473 | } | |
| 474 | ||
| 475 | /** | |
| 476 | * The repositories among `repoIds` with an open issue whose title `titled` selects: | |
| 477 | * one read per `CHUNK`. | |
| 478 | */ | |
| 479 | function reposTitled( | |
| 480 | db: Database, | |
| 481 | repoIds: readonly string[], | |
| 482 | titled: string, | |
| 459 | 483 | ): Set<string> { |
| 460 | 484 | const out = new Set<string>(); |
| 461 | 485 | for (let i = 0; i < repoIds.length; i += CHUNK) { |
| @@ -464,8 +488,7 @@ export function reposWithUmbrellas( | ||
| 464 | 488 | .query<{ repo_id: string }, string[]>( |
| 465 | 489 | `SELECT DISTINCT repo_id FROM issue |
| 466 | 490 | WHERE repo_id IN (${chunk.map((_, n) => `?${n + 1}`).join(",")}) |
| 467 | AND kind = 'issue' AND state = 'open' | |
| 468 | AND (title GLOB 'P[0-9]*' OR title LIKE 'Later%')`, | |
| 491 | AND kind = 'issue' AND state = 'open' AND ${titled}`, | |
| 469 | 492 | ) |
| 470 | 493 | .all(...chunk); |
| 471 | 494 | for (const row of rows) out.add(row.repo_id); |
src/web/studio/held.ts +3 −3
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { gateHold } from "../../core/gate_hold.ts"; |
| 8 | import { reposWithUmbrellas } from "../../core/pillars.ts"; | |
| 8 | import { reposWithGateTitle } from "../../core/pillars.ts"; | |
| 9 | 9 | import { canWrite, listReposOwnedBy, type Repo } from "../../core/repos.ts"; |
| 10 | 10 | import type { User } from "../../core/users.ts"; |
| 11 | 11 | import type { Ctx } from "../../http/context.ts"; |
| @@ -20,9 +20,9 @@ function holds(ctx: Ctx, user: User) { | ||
| 20 | 20 | const own = listReposOwnedBy(db, user.id); |
| 21 | 21 | const byId = new Map<string, Repo>(own.map((r) => [r.id, r])); |
| 22 | 22 | for (const r of writableAppsOf(ctx, user).repos) byId.set(r.id, r); |
| 23 | const withUmbrellas = reposWithUmbrellas(db, [...byId.keys()]); | |
| 23 | const withGate = reposWithGateTitle(db, [...byId.keys()]); | |
| 24 | 24 | const out = []; |
| 25 | for (const id of withUmbrellas) { | |
| 25 | for (const id of withGate) { | |
| 26 | 26 | const repo = byId.get(id)!; |
| 27 | 27 | if (!canWrite(db, repo, user)) continue; |
| 28 | 28 | const hold = gateHold(db, repo); |
test/pillars.test.ts +9 −1
| @@ -39,7 +39,7 @@ import { | ||
| 39 | 39 | type Issue, |
| 40 | 40 | } from "../src/core/issues.ts"; |
| 41 | 41 | import { backfillLanded } from "../src/core/carried.ts"; |
| 42 | import { pillarsOf, pillarView, pillarWindowStart } from "../src/core/pillars.ts"; | |
| 42 | import { pillarsOf, pillarView, reposWithGateTitle, pillarWindowStart } from "../src/core/pillars.ts"; | |
| 43 | 43 | import { askToLiveFor } from "../src/web/ask_to_live.ts"; |
| 44 | 44 | import { getRepoById, updateRepoSettings, type Repo } from "../src/core/repos.ts"; |
| 45 | 45 | import { createToken } from "../src/core/tokens.ts"; |
| @@ -231,6 +231,14 @@ describe("pillars", () => { | ||
| 231 | 231 | expect(set.later?.number).toBe(later.number); |
| 232 | 232 | }); |
| 233 | 233 | |
| 234 | test("the repositories with a gate-titled open issue come in one read; one without is left out", async () => { | |
| 235 | const other = await createRepo(app, alice, { name: "no-gate" }); | |
| 236 | expect(other.ok).toBe(true); | |
| 237 | if (!other.ok) return; | |
| 238 | const found = reposWithGateTitle(app.db, [repo.id, other.value.id]); | |
| 239 | expect([...found]).toEqual([repo.id]); | |
| 240 | }); | |
| 241 | ||
| 234 | 242 | test("linked under an umbrella, an issue carries the pillar's label, made on first use; unlinked, it does not", () => { |
| 235 | 243 | expect(listLabels(app.db, repo.id)).toEqual([]); |
| 236 | 244 | sandbox = issue("Sandbox every run"); |
test/snappy.test.ts +5 −4
| @@ -27,11 +27,12 @@ const P95_MS = 250; | ||
| 27 | 27 | const SQL = { mapOwner: 80, mapMember: 60, homeOwner: 220, homeMember: 180 }; |
| 28 | 28 | /** |
| 29 | 29 | * After a write every cache misses: what the grouped reads alone must hold. The home's was 260 |
| 30 | * until 2026-11-13: the lanes home reads its picture, its figures and the hosted forges on a cold | |
| 31 | * view, and the held line reads one Later gate per app (12 here). It measures 316 here; grouping the | |
| 32 | * per-app reads is #12310, which also brings this file out of SLOW. | |
| 30 | * until 2026-11-13: under `bun test` the lanes home reads its picture inline, on the request's | |
| 31 | * connection (about 300 here: `nextUp` per autonomous app); in production a worker reads it and the | |
| 32 | * request's own figure is about 50. The held line reads a Later gate only for an app that has a | |
| 33 | * gate-titled issue (`reposWithGateTitle`). | |
| 33 | 34 | */ |
| 34 | const COLD_SQL = { mapOwner: 450, homeOwner: 330 }; | |
| 35 | const COLD_SQL = { mapOwner: 450, homeOwner: 320 }; | |
| 35 | 36 | |
| 36 | 37 | let f: SnappyFixture; |
| 37 | 38 | const page = async (path: string, cookie?: string): Promise<string> => |
new above
offline