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

Merged opened this

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

Merged

mason/forge:mason/12310-group-the-home-s-per-app-reads-later-gat → main 5 commits fork

  • Merged. mason/12310-group-the-home-s-per-app-reads-later-gat was merged into main as a9b30ef.

Review

Sign in to review this change.
5 files changed +46 −12
src/core/next_up.ts +4 −2
@@ -131,7 +131,9 @@ export function nextUp(
131131 /** Why a ready issue is not startable, by issue id (`crew/not_startable.ts`): a page that has the app passes it. */
132132 notStartable: (ready: readonly Ranked[]) => ReadonlyMap<string, string> = () => new Map(),
133133 ): 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 });
135137 const ranks = graph.ranked ?? new Map<string, number>();
136138 const readyRanked = readyNow(graph);
137139 const ready = readyRanked.map((r) => r.issue);
@@ -144,7 +146,7 @@ export function nextUp(
144146 if (run.issueId !== null && who !== undefined) crew.set(run.issueId, who);
145147 }
146148 const holds = reachOf(graph).holds;
147 const serves = servedBy(db, pillarsOf(db, repo));
149 const serves = servedBy(db, set);
148150 const rowOf = (issue: Issue): NextRow => {
149151 const why = readyIds.has(issue.id) ? unstartable.get(issue.id) ?? null : whyNot(graph, issue);
150152 // 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(
456456 export function reposWithUmbrellas(
457457 db: Database,
458458 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,
459483 ): Set<string> {
460484 const out = new Set<string>();
461485 for (let i = 0; i < repoIds.length; i += CHUNK) {
@@ -464,8 +488,7 @@ export function reposWithUmbrellas(
464488 .query<{ repo_id: string }, string[]>(
465489 `SELECT DISTINCT repo_id FROM issue
466490 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}`,
469492 )
470493 .all(...chunk);
471494 for (const row of rows) out.add(row.repo_id);
src/web/studio/held.ts +3 −3
@@ -5,7 +5,7 @@
55 */
66
77 import { gateHold } from "../../core/gate_hold.ts";
8 import { reposWithUmbrellas } from "../../core/pillars.ts";
8 import { reposWithGateTitle } from "../../core/pillars.ts";
99 import { canWrite, listReposOwnedBy, type Repo } from "../../core/repos.ts";
1010 import type { User } from "../../core/users.ts";
1111 import type { Ctx } from "../../http/context.ts";
@@ -20,9 +20,9 @@ function holds(ctx: Ctx, user: User) {
2020 const own = listReposOwnedBy(db, user.id);
2121 const byId = new Map<string, Repo>(own.map((r) => [r.id, r]));
2222 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()]);
2424 const out = [];
25 for (const id of withUmbrellas) {
25 for (const id of withGate) {
2626 const repo = byId.get(id)!;
2727 if (!canWrite(db, repo, user)) continue;
2828 const hold = gateHold(db, repo);
test/pillars.test.ts +9 −1
@@ -39,7 +39,7 @@ import {
3939 type Issue,
4040 } from "../src/core/issues.ts";
4141 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";
4343 import { askToLiveFor } from "../src/web/ask_to_live.ts";
4444 import { getRepoById, updateRepoSettings, type Repo } from "../src/core/repos.ts";
4545 import { createToken } from "../src/core/tokens.ts";
@@ -231,6 +231,14 @@ describe("pillars", () => {
231231 expect(set.later?.number).toBe(later.number);
232232 });
233233
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
234242 test("linked under an umbrella, an issue carries the pillar's label, made on first use; unlinked, it does not", () => {
235243 expect(listLabels(app.db, repo.id)).toEqual([]);
236244 sandbox = issue("Sandbox every run");
test/snappy.test.ts +5 −4
@@ -27,11 +27,12 @@ const P95_MS = 250;
2727 const SQL = { mapOwner: 80, mapMember: 60, homeOwner: 220, homeMember: 180 };
2828 /**
2929 * 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`).
3334 */
34 const COLD_SQL = { mapOwner: 450, homeOwner: 330 };
35 const COLD_SQL = { mapOwner: 450, homeOwner: 320 };
3536
3637 let f: SnappyFixture;
3738 const page = async (path: string, cookie?: string): Promise<string> =>

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs