GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #15036 from developing-today/queue/23739-cf7-proje… · developing-today/code@36b8dae

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pm-stack/aggregator
    • src
      • server.ts
    • test
      • boot.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pm-stack/aggregator/src/server.ts‎

Copy file name to clipboardExpand all lines: pm-stack/aggregator/src/server.ts
+43-13Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,17 +1788,38 @@ async function roadmapContext() {
17881788
return { rows, items, pool: poolResult.pool, reconciliation, drill };
17891789
}
17901790

1791+
type SearchTimings = Record<string, number>;
1792+
1793+
async function withSearchTiming<T>(timings: SearchTimings, stage: string, run: () => T | Promise<T>): Promise<T> {
1794+
const started = performance.now();
1795+
try {
1796+
return await run();
1797+
} finally {
1798+
timings[stage] = performance.now() - started;
1799+
}
1800+
}
1801+
1802+
function withSearchTimings(response: Response, timings: SearchTimings): Response {
1803+
const value = Object.entries(timings)
1804+
.map(([stage, duration]) => `${stage};dur=${Math.max(0, duration).toFixed(2)}`)
1805+
.join(", ");
1806+
response.headers.set("server-timing", value);
1807+
return response;
1808+
}
1809+
17911810
async function searchContext(query: string) {
1811+
const timings: SearchTimings = {};
17921812
// #1212 slice 2: registry, DNS, services, and tier items join the
17931813
// board/roadmap subjects. Each extra source fails soft (empty on
1794-
// error) so one broken source never takes search down with it.
1814+
// error) so one broken source never takes search down with it. The
1815+
// source timings below overlap: these reads intentionally run in parallel.
17951816
const [board, rows, registry, dns, usage, orchestration] = await Promise.all([
1796-
source.board(),
1797-
source.roadmap(),
1798-
source.registry().catch(() => []),
1799-
source.dns().catch(() => null),
1800-
source.usage().catch(() => null),
1801-
source.orchestration().catch(() => null),
1817+
withSearchTiming(timings, "board", () => source.board()),
1818+
withSearchTiming(timings, "roadmap", () => source.roadmap()),
1819+
withSearchTiming(timings, "registry", () => source.registry().catch(() => [])),
1820+
withSearchTiming(timings, "dns", () => source.dns().catch(() => null)),
1821+
withSearchTiming(timings, "usage", () => source.usage().catch(() => null)),
1822+
withSearchTiming(timings, "orchestration", () => source.orchestration().catch(() => null)),
18021823
]);
18031824
const tierItems = orchestration ? [...orchestration.tiers.needsDrew, ...orchestration.tiers.needsOrchestrator] : [];
18041825
// Codex P2 on PR #7331: refs carried only by the slice-2 sources
@@ -1809,9 +1830,10 @@ async function searchContext(query: string) {
18091830
isValidRef,
18101831
);
18111832
const refs = [...new Set([...allRefs(board), ...allRefs(rows), ...extraRefs])];
1812-
const items = await source.items(refs);
1833+
const items = await withSearchTiming(timings, "items", () => source.items(refs));
18131834
const extras = { registry, dns, services: usage?.services ?? [], tierItems };
1814-
return { query, results: searchWork(board, rows, items, query, extras), items };
1835+
const results = await withSearchTiming(timings, "search", () => searchWork(board, rows, items, query, extras));
1836+
return { query, results, items, timings };
18151837
}
18161838

18171839
// #3321: watchdog gap-sync passes run whole and in observation
@@ -3994,12 +4016,20 @@ async function handler(req: Request, remoteAddress?: string): Promise<Response>
39944016
);
39954017
}
39964018
if (path === "/search") {
3997-
const { query, results, items } = await searchContext(url.searchParams.get("q") ?? "");
3998-
return html(renderSearch(query, results, items, prov(), provDetail()));
4019+
const started = performance.now();
4020+
const { query, results, items, timings } = await searchContext(url.searchParams.get("q") ?? "");
4021+
const body = await withSearchTiming(timings, "render", () => renderSearch(query, results, items, prov(), provDetail()));
4022+
timings.total = performance.now() - started;
4023+
return withSearchTimings(html(body), timings);
39994024
}
40004025
if (path === "/api/search.json") {
4001-
const { query, results } = await searchContext(url.searchParams.get("q") ?? "");
4002-
return json({ query: query.trim(), total: results.length, results });
4026+
const started = performance.now();
4027+
const { query, results, timings } = await searchContext(url.searchParams.get("q") ?? "");
4028+
const response = await withSearchTiming(timings, "serialize", () =>
4029+
json({ query: query.trim(), total: results.length, results }),
4030+
);
4031+
timings.total = performance.now() - started;
4032+
return withSearchTimings(response, timings);
40034033
}
40044034
if (path === "/api/registry.json") {
40054035
const records = await source.registry();
Collapse file

‎pm-stack/aggregator/test/boot.test.ts‎

Copy file name to clipboardExpand all lines: pm-stack/aggregator/test/boot.test.ts
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ describe("server boots from fixtures", () => {
5757
expect(body.source.board).toBe("fixtures");
5858
});
5959

60+
test("search routes expose in-process stage timings", async () => {
61+
// Oracle: each named timing is recorded by the search path while it runs
62+
// and is returned in the standard Server-Timing response header.
63+
const expected = ["board", "roadmap", "registry", "dns", "usage", "orchestration", "items", "search"];
64+
const json = await fetch(`http://127.0.0.1:${port}/api/search.json?q=fleet`);
65+
expect(json.status).toBe(200);
66+
const jsonTiming = json.headers.get("server-timing") ?? "";
67+
for (const stage of [...expected, "serialize", "total"]) {
68+
expect(jsonTiming).toMatch(new RegExp(`(?:^|,\\s*)${stage};dur=\\d+(?:\\.\\d+)?`));
69+
}
70+
71+
const page = await fetch(`http://127.0.0.1:${port}/search?q=fleet`);
72+
expect(page.status).toBe(200);
73+
const pageTiming = page.headers.get("server-timing") ?? "";
74+
for (const stage of [...expected, "render", "total"]) {
75+
expect(pageTiming).toMatch(new RegExp(`(?:^|,\\s*)${stage};dur=\\d+(?:\\.\\d+)?`));
76+
}
77+
});
78+
6079
test("item JSON exposes ready-for-agent dispatch state and provenance", async () => {
6180
const id = "kaneo:code/fx0dispatchtrial0000107";
6281
const res = await fetch(`http://127.0.0.1:${port}/api/item/${encodeURIComponent(id)}.json`);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.