Public: anyone can read this; the crew can change it.
The settings page's Server-Timing names its phases: session, each read, render #3465
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3457-the-settings-page-s-server-timing-names → main 1 commit fork
2 files
changed +68
−3
src/web/pages/account.ts +14 −3
| @@ -39,6 +39,7 @@ import { ADMIN_TOKEN_WORDS, listTokens, type TokenScope } from "../../core/token | ||
| 39 | 39 | import type { CommitEmail, User } from "../../core/users.ts"; |
| 40 | 40 | import { isStandInEmail } from "../../core/users.ts"; |
| 41 | 41 | import { cookieValue, type Ctx } from "../../http/context.ts"; |
| 42 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 42 | 43 | import { sshCommand } from "../../ssh/command.ts"; |
| 43 | 44 | import { |
| 44 | 45 | settingsLayout, |
| @@ -338,16 +339,26 @@ function profileView(ctx: Ctx, values: ProfileForm): Html { | ||
| 338 | 339 | // GET /settings |
| 339 | 340 | export function accountPage(ctx: Ctx): Response { |
| 340 | 341 | if (!ctx.auth.user) return signInFirst(ctx); |
| 341 | const pair = everydayLine(ctx, ctx.auth.user); | |
| 342 | return accountShell( | |
| 342 | const user = ctx.auth.user; | |
| 343 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 344 | // Read in the order the page lays them out; each phase is named for what it reads. | |
| 345 | const pair = timePhase(ctx.request, "everyday", () => everydayLine(ctx, user)); | |
| 346 | const profile = timePhase(ctx.request, "profile", () => profileView(ctx, currentProfile(user))); | |
| 347 | const edge = timePhase(ctx.request, "edge", () => edgeLinkView(ctx)); | |
| 348 | const parent = timePhase(ctx.request, "parent", () => parentLinkView(ctx)); | |
| 349 | const notify = timePhase(ctx.request, "notify", () => notifyView(ctx)); | |
| 350 | const rendering = performance.now(); | |
| 351 | const response = accountShell( | |
| 343 | 352 | ctx, |
| 344 | 353 | "profile", |
| 345 | 354 | "Settings", |
| 346 | html`${pair}${profileView(ctx, currentProfile(ctx.auth.user))}${edgeLinkView(ctx)}${parentLinkView(ctx)}${notifyView(ctx)}`, | |
| 355 | html`${pair}${profile}${edge}${parent}${notify}`, | |
| 347 | 356 | 200, |
| 348 | 357 | // The everyday form makes its account with a passkey (#1890). |
| 349 | 358 | pair ? passkeyJs : undefined, |
| 350 | 359 | ); |
| 360 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 361 | return response; | |
| 351 | 362 | } |
| 352 | 363 | |
| 353 | 364 | // POST /settings/notify |
test/account-timing.test.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** `GET /settings` names session, each read and render in Server-Timing (#3457). */ | |
| 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 { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createUser } from "../src/core/users.ts"; | |
| 8 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 9 | import { proveAll } from "./helpers/verified.ts"; | |
| 10 | import { quietLogs } from "./helpers/globals.ts"; | |
| 11 | ||
| 12 | quietLogs(); | |
| 13 | ||
| 14 | let root = ""; | |
| 15 | let app: App; | |
| 16 | let servers: Servers; | |
| 17 | ||
| 18 | beforeAll(async () => { | |
| 19 | root = mkdtempSync(join(tmpdir(), "forge-account-timing-")); | |
| 20 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); | |
| 21 | const u = await createUser(app.db, { | |
| 22 | origin: "seed", | |
| 23 | trusted: true, | |
| 24 | username: "alice", | |
| 25 | email: "[email protected]", | |
| 26 | password: "a-good-passphrase", | |
| 27 | adminIfFirst: true, | |
| 28 | }); | |
| 29 | if (!u.ok) throw new Error(u.error); | |
| 30 | proveAll(app); | |
| 31 | servers = await serve(app); | |
| 32 | }); | |
| 33 | afterAll(() => { | |
| 34 | servers.stop(); | |
| 35 | app.close(); | |
| 36 | rmSync(root, { recursive: true, force: true }); | |
| 37 | }); | |
| 38 | ||
| 39 | test("GET /settings names its phases", async () => { | |
| 40 | const signin = await fetch(`${servers.url}/signin`, { | |
| 41 | method: "POST", | |
| 42 | headers: { origin: servers.url }, | |
| 43 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 44 | redirect: "manual", | |
| 45 | }); | |
| 46 | const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 47 | const res = await fetch(`${servers.url}/settings`, { headers: { cookie } }); | |
| 48 | const body = await res.text(); | |
| 49 | expect(res.status).toBe(200); | |
| 50 | expect(body).toContain("<h1>Settings</h1>"); | |
| 51 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 52 | for (const name of ["app", "session", "everyday", "profile", "edge", "parent", "notify", "render"]) | |
| 53 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 54 | }); |
new above
offline