Public: anyone can read this; the crew can change it.
The new pull page names its Server-Timing phases: session, the compare, render #3641
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3634-the-new-pull-page-names-its-server-timin → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +71
−1
src/web/pages/pulls.ts +8 −1
| @@ -12,6 +12,7 @@ import { | ||
| 12 | 12 | forkParentFor, |
| 13 | 13 | type Repo, |
| 14 | 14 | } from "../../core/repos.ts"; |
| 15 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | |
| 15 | 16 | import { repoDir } from "../../git/repos.ts"; |
| 16 | 17 | import type { Ctx } from "../../http/context.ts"; |
| 17 | 18 | import { |
| @@ -148,11 +149,15 @@ async function composeContext(ctx: Ctx, repo: Repo, forceSelf: boolean) { | ||
| 148 | 149 | |
| 149 | 150 | // GET /:owner/:name/pulls/new |
| 150 | 151 | export async function newPullPage(ctx: Ctx): Promise<Response> { |
| 152 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 151 | 153 | const repo = loadRepo(ctx); |
| 152 | 154 | if (!repo) return notFoundPage(ctx); |
| 153 | 155 | if (!ctx.auth.user) return signInFirst(ctx); |
| 154 | 156 | const forceSelf = ctx.url.searchParams.get("self") !== null; |
| 157 | const comparing = performance.now(); | |
| 155 | 158 | const c = await composeContext(ctx, repo, forceSelf); |
| 159 | notePhase(ctx.request, "compare", performance.now() - comparing); | |
| 160 | const rendering = performance.now(); | |
| 156 | 161 | // The branches page proposes a branch by linking here with it named, so |
| 157 | 162 | // "New pull" from a row arrives with that row already chosen. |
| 158 | 163 | const wantedHead = ctx.url.searchParams.get("head") ?? ""; |
| @@ -197,13 +202,15 @@ export async function newPullPage(ctx: Ctx): Promise<Response> { | ||
| 197 | 202 | action: btn("Back to code", { href: repoBase(repo) }), |
| 198 | 203 | })} |
| 199 | 204 | </div>`; |
| 200 | return page({ | |
| 205 | const response = page({ | |
| 201 | 206 | ctx, |
| 202 | 207 | title: `New pull request · ${repo.name}`, |
| 203 | 208 | crumbs: crumbsFor(repo), |
| 204 | 209 | palette: repoPalette(ctx, repo), |
| 205 | 210 | body, |
| 206 | 211 | }); |
| 212 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 213 | return response; | |
| 207 | 214 | } |
| 208 | 215 | |
| 209 | 216 | const COMPOSE_ERRORS: Record<string, string> = { |
test/new-pull-timing.test.ts added +63
| @@ -0,0 +1,63 @@ | ||
| 1 | /** `/:owner/:name/pulls/new`'s Server-Timing names its phases (#3634). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { createSession } from "../src/core/sessions.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { quietLogs } from "./helpers/globals.ts"; | |
| 12 | ||
| 13 | quietLogs(); | |
| 14 | ||
| 15 | let dataDir: string; | |
| 16 | let app: App; | |
| 17 | let servers: Servers; | |
| 18 | let cookie = ""; | |
| 19 | const cells = process.env["FORGE_CELLS"]; | |
| 20 | ||
| 21 | beforeAll(async () => { | |
| 22 | process.env["FORGE_CELLS"] = "off"; | |
| 23 | dataDir = await mkdtemp(join(tmpdir(), "forge-new-pull-timing-")); | |
| 24 | app = createApp({ dataDir, port: 0 }); | |
| 25 | servers = await serve(app); | |
| 26 | const made = await createUser(app.db, { | |
| 27 | origin: "seed", | |
| 28 | trusted: true, | |
| 29 | username: "alice", | |
| 30 | email: "[email protected]", | |
| 31 | password: "a-good-passphrase", | |
| 32 | adminIfFirst: true, | |
| 33 | }); | |
| 34 | if (!made.ok) throw new Error(String(made.error)); | |
| 35 | const alice = made.value; | |
| 36 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 37 | const repo = await createRepo(app, alice, { name: "r", visibility: "public" }); | |
| 38 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 39 | for (const [branch, file] of [[undefined, "forge.json"], ["topic", "t.txt"]] as const) { | |
| 40 | const done = await commitToBranch(app, alice, repo.value, { | |
| 41 | ...(branch === undefined ? {} : { branch }), | |
| 42 | message: "change", | |
| 43 | files: [{ path: file, content: file === "forge.json" ? "{}" : "x" }], | |
| 44 | }); | |
| 45 | if (!done.ok) throw new Error(JSON.stringify(done.error)); | |
| 46 | } | |
| 47 | }); | |
| 48 | ||
| 49 | afterAll(async () => { | |
| 50 | await servers.stop(); | |
| 51 | app.close(); | |
| 52 | if (cells === undefined) delete process.env["FORGE_CELLS"]; | |
| 53 | else process.env["FORGE_CELLS"] = cells; | |
| 54 | await rm(dataDir, { recursive: true, force: true }); | |
| 55 | }); | |
| 56 | ||
| 57 | test("the new pull page names session, compare and render after app", async () => { | |
| 58 | const res = await fetch(`${servers.url}/alice/r/pulls/new`, { headers: { cookie } }); | |
| 59 | expect(res.status).toBe(200); | |
| 60 | await res.arrayBuffer(); | |
| 61 | const names = (res.headers.get("server-timing") ?? "").split(", ").map((p) => p.split(";")[0]!); | |
| 62 | expect(names.slice(names.indexOf("app") + 1)).toEqual(["session", "compare", "render"]); | |
| 63 | }); |
new above
offline
loadRepo on the next line is a read and is not timed; consider a phase for it so the phases account for the request.