Public: anyone can read this; the crew can change it.
A repository's commits list's Server-Timing names its phases: session, each read, render #4036
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3277-a-repository-s-commits-list-s-server-tim → main 5 commits fork
3 files
changed +73
−7
docs/CACHING.md +3
| @@ -91,6 +91,9 @@ After #2716 (same fixture, same machine, `--n 30`, warm; `/` unchanged): | ||
| 91 | 91 | What is left is rendering the ~1 MB of SVG (25 ms), which rule 3 keeps |
| 92 | 92 | per request. |
| 93 | 93 | |
| 94 | `/:owner/:name/commits` names `session`, `repo`, `log`, `refs` and `render` | |
| 95 | the same way (#3392). | |
| 96 | ||
| 94 | 97 | `/map`'s `Server-Timing` names where that goes (#3159): `app` is the total, |
| 95 | 98 | then `session`, `lanes` (the cache lookups, and the build on a miss, less the |
| 96 | 99 | layout inside it), `layout` (graph layout on a miss) and `render`. Their sum |
src/web/pages/commits.ts +13 −7
| @@ -14,7 +14,7 @@ import { diffCommit, type Diff } from "../../git/diff.ts"; | ||
| 14 | 14 | import { isSafeOid, isSafeRef, isSafeTreePath } from "../../git/guard.ts"; |
| 15 | 15 | import { commitLog } from "../../git/read.ts"; |
| 16 | 16 | import { repoDir } from "../../git/repos.ts"; |
| 17 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | |
| 17 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; | |
| 18 | 18 | import type { Ctx } from "../../http/context.ts"; |
| 19 | 19 | import type { Commit } from "../../view/source.ts"; |
| 20 | 20 | import { loadRepo, notFoundPage, scopeHeader } from "../chrome.ts"; |
| @@ -172,7 +172,8 @@ export const noCommits = (later: boolean): Html => | ||
| 172 | 172 | |
| 173 | 173 | // GET /:owner/:name/commits?ref=&path=&page= |
| 174 | 174 | export async function commitsPage(ctx: Ctx): Promise<Response> { |
| 175 | const repo = loadRepo(ctx); | |
| 175 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 176 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); | |
| 176 | 177 | if (!repo) return notFoundPage(ctx); |
| 177 | 178 | const scope = localScope(ctx, repo); |
| 178 | 179 | const dir = repoDir(ctx.app.reposRoot, repo.ownerName, repo.name); |
| @@ -191,12 +192,13 @@ export async function commitsPage(ctx: Ctx): Promise<Response> { | ||
| 191 | 192 | // Path filtering and offset paging are things git does and a provider API |
| 192 | 193 | // does not, so the local page keeps its own log read rather than pretending |
| 193 | 194 | // the shared source could answer this. |
| 194 | const log = await commitLog(dir, ref, { | |
| 195 | const log = await timePhaseAsync(ctx.request, "log", () => commitLog(dir, ref, { | |
| 195 | 196 | limit: PER_PAGE + 1, |
| 196 | 197 | skip: (num - 1) * PER_PAGE, |
| 197 | 198 | ...(path !== "" ? { path } : {}), |
| 198 | }); | |
| 199 | const refs = await refSet(dir); | |
| 199 | })); | |
| 200 | const refs = await timePhaseAsync(ctx.request, "refs", () => refSet(dir)); | |
| 201 | const rendering = performance.now(); | |
| 200 | 202 | |
| 201 | 203 | const query = (n: number) => { |
| 202 | 204 | const params = new URLSearchParams({ ref }); |
| @@ -211,7 +213,7 @@ export async function commitsPage(ctx: Ctx): Promise<Response> { | ||
| 211 | 213 | }); |
| 212 | 214 | |
| 213 | 215 | if (!log.ok || log.value.length === 0) { |
| 214 | return page({ | |
| 216 | const response = page({ | |
| 215 | 217 | ctx, |
| 216 | 218 | title: `Commits · ${repo.name}`, |
| 217 | 219 | crumbs: scope.crumbs, |
| @@ -220,6 +222,8 @@ export async function commitsPage(ctx: Ctx): Promise<Response> { | ||
| 220 | 222 | ${noCommits(num > 1)} ${liveMount({ repo: base })}`, |
| 221 | 223 | scriptJs: liveClientJs, |
| 222 | 224 | }); |
| 225 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 226 | return response; | |
| 223 | 227 | } |
| 224 | 228 | |
| 225 | 229 | const commits = log.value.slice(0, PER_PAGE); |
| @@ -233,7 +237,7 @@ export async function commitsPage(ctx: Ctx): Promise<Response> { | ||
| 233 | 237 | note: `Page ${num}`, |
| 234 | 238 | })} |
| 235 | 239 | ${liveMount({ repo: base })}`; |
| 236 | return page({ | |
| 240 | const response = page({ | |
| 237 | 241 | ctx, |
| 238 | 242 | title: `Commits · ${repo.name}`, |
| 239 | 243 | crumbs: scope.crumbs, |
| @@ -241,6 +245,8 @@ export async function commitsPage(ctx: Ctx): Promise<Response> { | ||
| 241 | 245 | body, |
| 242 | 246 | scriptJs: liveClientJs, |
| 243 | 247 | }); |
| 248 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 249 | return response; | |
| 244 | 250 | } |
| 245 | 251 | |
| 246 | 252 | // GET /:owner/:name/commit/:oid — one commit's metadata and its diff. |
test/commits-timing.test.ts added +57
| @@ -0,0 +1,57 @@ | ||
| 1 | /** `/:owner/:name/commits` names session, repo, log, refs and render in Server-Timing (#3392). */ | |
| 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-commits-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/commits 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/commits`, { headers: { cookie } }); | |
| 51 | const body = await res.text(); | |
| 52 | expect(res.status).toBe(200); | |
| 53 | expect(body).toContain("Commits"); | |
| 54 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 55 | for (const name of ["app", "session", "repo", "log", "refs", "render"]) | |
| 56 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 57 | }); |
new above
offline