Public: anyone can read this; the crew can change it.
The admin limits page's Server-Timing names its phases: session, each read, render #3467
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3443-the-admin-limits-page-s-server-timing-na → main 1 commit fork
2 files
changed +64
−5
src/web/pages/admin-limits.ts +10 −5
| @@ -13,6 +13,7 @@ import { changeSignup, readSignup } from "../../actions/signup.ts"; | ||
| 13 | 13 | import { SIGNUP_MODES } from "../../settings/signup.ts"; |
| 14 | 14 | import { QUOTA_KEYS } from "../../settings/quotas.ts"; |
| 15 | 15 | import type { Ctx } from "../../http/context.ts"; |
| 16 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 16 | 17 | import { notFoundPage, settingsLayout } from "../chrome.ts"; |
| 17 | 18 | import { field, readForm } from "../form.ts"; |
| 18 | 19 | import { html, when } from "../html.ts"; |
| @@ -22,8 +23,13 @@ import { accountSections } from "./origins.ts"; | ||
| 22 | 23 | |
| 23 | 24 | // GET /admin/limits |
| 24 | 25 | export function limitsPage(ctx: Ctx): Response { |
| 25 | const listed = listLimits(ctx.app, ctx.auth.user); | |
| 26 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 27 | const listed = timePhase(ctx.request, "limits", () => listLimits(ctx.app, ctx.auth.user)); | |
| 26 | 28 | if (!listed.ok) return notFoundPage(ctx); |
| 29 | const quotas = timePhase(ctx.request, "quotas", () => readQuotas(ctx.app, ctx.auth.user)); | |
| 30 | const signup = timePhase(ctx.request, "signup", () => readSignup(ctx.app, ctx.auth.user)); | |
| 31 | const invites = timePhase(ctx.request, "invites", () => listInviteLinks(ctx.app, ctx.auth.user)); | |
| 32 | const rendering = performance.now(); | |
| 27 | 33 | const { limits, changes } = listed.value; |
| 28 | 34 | const rows = limits.map((l) => |
| 29 | 35 | row({ |
| @@ -75,7 +81,6 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 75 | 81 | meta: html`${c.actorName === "" ? "someone" : c.actorName} · ${time(c.at)}`, |
| 76 | 82 | }), |
| 77 | 83 | ); |
| 78 | const quotas = readQuotas(ctx.app, ctx.auth.user); | |
| 79 | 84 | const quotaHistory = (quotas.ok ? quotas.value.changes : []).map((c) => |
| 80 | 85 | row({ |
| 81 | 86 | lead: icon("history"), |
| @@ -118,7 +123,6 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 118 | 123 | pad: false, |
| 119 | 124 | }, |
| 120 | 125 | ); |
| 121 | const signup = readSignup(ctx.app, ctx.auth.user); | |
| 122 | 126 | const signupHistory = (signup.ok ? signup.value.changes : []).map((c) => |
| 123 | 127 | row({ |
| 124 | 128 | lead: icon("history"), |
| @@ -152,7 +156,6 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 152 | 156 | pad: false, |
| 153 | 157 | }, |
| 154 | 158 | ); |
| 155 | const invites = listInviteLinks(ctx.app, ctx.auth.user); | |
| 156 | 159 | const inviteRows = (invites.ok ? invites.value : []).map((i) => |
| 157 | 160 | row({ |
| 158 | 161 | lead: icon("activity"), |
| @@ -226,7 +229,7 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 226 | 229 | pad: false, |
| 227 | 230 | }, |
| 228 | 231 | )}`; |
| 229 | return page({ | |
| 232 | const response = page({ | |
| 230 | 233 | ctx, |
| 231 | 234 | title: "Limits", |
| 232 | 235 | body: html`<div class="page-head"><h1>Limits</h1></div> |
| @@ -236,6 +239,8 @@ export function limitsPage(ctx: Ctx): Response { | ||
| 236 | 239 | "Account settings", |
| 237 | 240 | )}`, |
| 238 | 241 | }); |
| 242 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 243 | return response; | |
| 239 | 244 | } |
| 240 | 245 | |
| 241 | 246 | // POST /admin/limits |
test/admin-limits-timing.test.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** `GET /admin/limits` names session, limits, quotas, signup, invites and render in Server-Timing (#3443). */ | |
| 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-admin-limits-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 /admin/limits 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}/admin/limits`, { headers: { cookie } }); | |
| 48 | const body = await res.text(); | |
| 49 | expect(res.status).toBe(200); | |
| 50 | expect(body).toContain("<h1>Limits</h1>"); | |
| 51 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 52 | for (const name of ["app", "session", "limits", "quotas", "signup", "invites", "render"]) | |
| 53 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 54 | }); |
new above
offline