Public: anyone can read this; the crew can change it.
A repository's branches list's Server-Timing names its phases: session, each read, render #3396
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3278-a-repository-s-branches-list-s-server-ti → main 2 commits fork 1 thread · 1 unresolved
2 files
changed +65
−3
src/web/pages/branches.ts +8 −3
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | import { createBranch, deleteBranch } from "../../actions/branches.ts"; |
| 19 | 19 | import type { Repo } from "../../core/repos.ts"; |
| 20 | import { notePhase, takeSessionTime, timePhaseAsync } from "../../core/route_timing.ts"; | |
| 20 | 21 | import { listBranches, type BranchInfo } from "../../git/branches.ts"; |
| 21 | 22 | import { commitLog, type Commit } from "../../git/read.ts"; |
| 22 | 23 | import { repoDir } from "../../git/repos.ts"; |
| @@ -244,10 +245,12 @@ export async function renderBranches( | ||
| 244 | 245 | scope: RepoScope, |
| 245 | 246 | banner?: Html, |
| 246 | 247 | ): Promise<Response> { |
| 248 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 247 | 249 | const [{ rows, compared }, refs] = await Promise.all([ |
| 248 | branchRows(ctx, scope), | |
| 249 | refSetFrom(scope.source), | |
| 250 | timePhaseAsync(ctx.request, "branches", () => branchRows(ctx, scope)), | |
| 251 | timePhaseAsync(ctx.request, "refs", () => refSetFrom(scope.source)), | |
| 250 | 252 | ]); |
| 253 | const rendering = performance.now(); | |
| 251 | 254 | const from = ctx.url.searchParams.get("from") ?? scope.facts.defaultBranch; |
| 252 | 255 | const all = [...refs.branches, ...refs.tags]; |
| 253 | 256 | const startFrom = all.includes(from) ? from : scope.facts.defaultBranch; |
| @@ -287,7 +290,7 @@ export async function renderBranches( | ||
| 287 | 290 | </div> |
| 288 | 291 | ${when(scope.kind === "local", () => liveMount({ repo: scope.base }))}`; |
| 289 | 292 | |
| 290 | return page({ | |
| 293 | const response = page({ | |
| 291 | 294 | ctx, |
| 292 | 295 | title: `Branches · ${scope.facts.name}`, |
| 293 | 296 | crumbs: scope.crumbs, |
| @@ -295,6 +298,8 @@ export async function renderBranches( | ||
| 295 | 298 | body, |
| 296 | 299 | ...(scope.kind === "local" ? { scriptJs: liveClientJs } : {}), |
| 297 | 300 | }); |
| 301 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 302 | return response; | |
| 298 | 303 | } |
| 299 | 304 | |
| 300 | 305 | const CREATE_ERRORS: Record<string, string> = { |
test/branches-timing.test.ts added +57
| @@ -0,0 +1,57 @@ | ||
| 1 | /** `/:owner/:name/branches` names session, branches, refs and render in Server-Timing (#3278). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createRepo } from "../src/actions/repos.ts"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { createUser } from "../src/core/users.ts"; | |
| 9 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 10 | import { proveAll } from "./helpers/verified.ts"; | |
| 11 | import { quietLogs } from "./helpers/globals.ts"; | |
| 12 | ||
| 13 | quietLogs(); | |
| 14 | ||
| 15 | let root = ""; | |
| 16 | let app: App; | |
| 17 | let servers: Servers; | |
| 18 | ||
| 19 | beforeAll(async () => { | |
| 20 | root = mkdtempSync(join(tmpdir(), "forge-branches-timing-")); | |
| 21 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); | |
| 22 | const u = await createUser(app.db, { | |
| 23 | origin: "seed", | |
| 24 | trusted: true, | |
| 25 | username: "alice", | |
| 26 | email: "[email protected]", | |
| 27 | password: "a-good-passphrase", | |
| 28 | adminIfFirst: true, | |
| 29 | }); | |
| 30 | if (!u.ok) throw new Error(u.error); | |
| 31 | proveAll(app); | |
| 32 | const made = await createRepo(app, { id: u.value.id, username: "alice" } as never, { name: "forge" }); | |
| 33 | if (!made.ok) throw new Error(made.error); | |
| 34 | servers = await serve(app); | |
| 35 | }); | |
| 36 | afterAll(() => { | |
| 37 | servers.stop(); | |
| 38 | app.close(); | |
| 39 | rmSync(root, { recursive: true, force: true }); | |
| 40 | }); | |
| 41 | ||
| 42 | test("GET /:owner/:name/branches names its phases", async () => { | |
| 43 | const signin = await fetch(`${servers.url}/signin`, { | |
| 44 | method: "POST", | |
| 45 | headers: { origin: servers.url }, | |
| 46 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 47 | redirect: "manual", | |
| 48 | }); | |
| 49 | const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 50 | const res = await fetch(`${servers.url}/alice/forge/branches`, { headers: { cookie } }); | |
| 51 | const body = await res.text(); | |
| 52 | expect(res.status).toBe(200); | |
| 53 | expect(body).toContain("No branches yet"); | |
| 54 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 55 | for (const name of ["app", "session", "branches", "refs", "render"]) | |
| 56 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 57 | }); |
new above
offline
This header names session, repo, plan, seats and render, but the page emits session, branches, refs and render. Reword it, and cite this issue rather than #3281.