Public: anyone can read this; the crew can change it.
A repository's tell page's Server-Timing names its phases: session, each read, render #3538
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3508-a-repository-s-tell-page-s-server-timing → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +76
−10
src/web/studio/tell_here.ts +18 −10
| @@ -11,15 +11,20 @@ import { parseFrom } from "../../actions/tell.ts"; | ||
| 11 | 11 | import { mayDirectCrew } from "../../crew/direct.ts"; |
| 12 | 12 | import type { Ctx } from "../../http/context.ts"; |
| 13 | 13 | import { crumbsFor, loadRepo, notFoundPage, pageHead, repoBase, signInFirst } from "../chrome.ts"; |
| 14 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 14 | 15 | import { html } from "../html.ts"; |
| 15 | 16 | import { fragment, page } from "../layout.ts"; |
| 16 | 17 | import { composer } from "../pages/thread.ts"; |
| 17 | 18 | |
| 18 | 19 | export function tellHerePage(ctx: Ctx): Response { |
| 19 | const repo = loadRepo(ctx); | |
| 20 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 21 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); | |
| 20 | 22 | if (!repo) return notFoundPage(ctx); |
| 21 | 23 | if (!ctx.auth.user) return signInFirst(ctx); |
| 22 | if (!mayDirectCrew(ctx.app.db, repo, ctx.auth.user)) return notFoundPage(ctx); | |
| 24 | const user = ctx.auth.user; | |
| 25 | const may = timePhase(ctx.request, "access", () => mayDirectCrew(ctx.app.db, repo, user)); | |
| 26 | if (!may) return notFoundPage(ctx); | |
| 27 | const rendering = performance.now(); | |
| 23 | 28 | const from = parseFrom(ctx.url.searchParams.get("from") ?? undefined) ?? null; |
| 24 | 29 | // The page of the app the toolbar was pressed on, and its pull: both |
| 25 | 30 | // checked here and again when the tell is sent. |
| @@ -44,12 +49,15 @@ export function tellHerePage(ctx: Ctx): Response { | ||
| 44 | 49 | ...(where?.pull === undefined ? {} : { pull: where.pull }), |
| 45 | 50 | }, |
| 46 | 51 | }); |
| 47 | if (ctx.url.searchParams.get("in") === "place") | |
| 48 | return fragment(box, { request: ctx.request }); | |
| 49 | return page({ | |
| 50 | ctx, | |
| 51 | title: `Tell the crew · ${repo.name}`, | |
| 52 | crumbs: crumbsFor(repo), | |
| 53 | body: html`${pageHead("Tell the crew")}${box}`, | |
| 54 | }); | |
| 52 | const response = | |
| 53 | ctx.url.searchParams.get("in") === "place" | |
| 54 | ? fragment(box, { request: ctx.request }) | |
| 55 | : page({ | |
| 56 | ctx, | |
| 57 | title: `Tell the crew · ${repo.name}`, | |
| 58 | crumbs: crumbsFor(repo), | |
| 59 | body: html`${pageHead("Tell the crew")}${box}`, | |
| 60 | }); | |
| 61 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 62 | return response; | |
| 55 | 63 | } |
test/tell-here-timing.test.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | /** `/:owner/:name/tell` names session, repo, access and render in Server-Timing (#3508). */ | |
| 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-tell-here-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/tell 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 | for (const query of ["", "?in=place"]) { | |
| 51 | const res = await fetch(`${servers.url}/alice/forge/tell${query}`, { headers: { cookie } }); | |
| 52 | await res.text(); | |
| 53 | expect(res.status).toBe(200); | |
| 54 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 55 | for (const name of ["app", "session", "repo", "access", "render"]) | |
| 56 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 57 | } | |
| 58 | }); |
new above
offline
Header cites #3508; this pull is #3538. Correct the reference.