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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/3278-a-repository-s-branches-list-s-server-ti → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/3278-a-repository-s-branches-list-s-server-ti was merged into main as 9da88cd.

Review

Sign in to review this change.
2 files changed +65 −3
src/web/pages/branches.ts +8 −3
@@ -17,6 +17,7 @@
1717
1818 import { createBranch, deleteBranch } from "../../actions/branches.ts";
1919 import type { Repo } from "../../core/repos.ts";
20 import { notePhase, takeSessionTime, timePhaseAsync } from "../../core/route_timing.ts";
2021 import { listBranches, type BranchInfo } from "../../git/branches.ts";
2122 import { commitLog, type Commit } from "../../git/read.ts";
2223 import { repoDir } from "../../git/repos.ts";
@@ -244,10 +245,12 @@ export async function renderBranches(
244245 scope: RepoScope,
245246 banner?: Html,
246247 ): Promise<Response> {
248 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
247249 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)),
250252 ]);
253 const rendering = performance.now();
251254 const from = ctx.url.searchParams.get("from") ?? scope.facts.defaultBranch;
252255 const all = [...refs.branches, ...refs.tags];
253256 const startFrom = all.includes(from) ? from : scope.facts.defaultBranch;
@@ -287,7 +290,7 @@ export async function renderBranches(
287290 </div>
288291 ${when(scope.kind === "local", () => liveMount({ repo: scope.base }))}`;
289292
290 return page({
293 const response = page({
291294 ctx,
292295 title: `Branches · ${scope.facts.name}`,
293296 crumbs: scope.crumbs,
@@ -295,6 +298,8 @@ export async function renderBranches(
295298 body,
296299 ...(scope.kind === "local" ? { scriptJs: liveClientJs } : {}),
297300 });
301 notePhase(ctx.request, "render", performance.now() - rendering);
302 return response;
298303 }
299304
300305 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). */
outdated

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.

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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs