Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@modelcontextprotocol/sdk": "^1.26.0",
"@react-three/fiber": "^9.6.1",
"@vercel/analytics": "^2.0.1",
"@vercel/blob": "^1.0.0",
"cmdk": "^1.1.1",
"fuse.js": "^7.4.2",
"ioredis": "^5.11.1",
Expand Down
59 changes: 59 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions src/app/api/internal/revalidate-aggregate/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { timingSafeEqual } from "node:crypto";
import { revalidateTag } from "next/cache";
import { NextResponse } from "next/server";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

/**
* Worker-driven CDN cache purge for the aggregate bench snapshot.
*
* The materialize worker POSTs here after successfully uploading a fresh
* `bench-aggregate/latest.json` to Vercel Blob. This route invalidates
* the `bench-aggregate` cache tag so the next site request re-fetches
* the Blob URL, instead of waiting the ~60 s Blob overwrite propagation
* window or the ISR revalidate boundary.
*
* Auth: bearer token in `Authorization` header, `REVALIDATE_TOKEN` env,
* timing-safe compare. Fails closed when the env is missing.
*/
export async function POST(req: Request): Promise<NextResponse> {
const secret = (process.env.REVALIDATE_TOKEN ?? "").trim();
if (!secret) {
return NextResponse.json(
{ error: "no_secret_configured" },
{ status: 503 },
);
}
const header = (req.headers.get("authorization") ?? "").trim();
const expected = `Bearer ${secret}`;
const ok =
header.length === expected.length &&
timingSafeEqual(Buffer.from(header), Buffer.from(expected));
if (!ok) {
return NextResponse.json({ error: "unauthorized" }, { status: 401 });
}
// Next 16's revalidateTag takes a required cache-profile argument.
// "default" applies the standard purge semantics for the CDN + ISR
// cache layers this route is meant to invalidate.
revalidateTag("bench-aggregate", "default");
return NextResponse.json({ revalidated: true, tag: "bench-aggregate" });
}
20 changes: 20 additions & 0 deletions worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { CHAINS } from "@/lib/chains";
import { buildFeaturedLeadersFromStore } from "@/lib/search-featured";
import type { Benchmark, MetricPanel } from "@/types/benchmark";
import type { Spec } from "@/lib/spec-schema";
import { publishAggregateBlob } from "./publish-blob";

const SWEEP_SEC = Number(process.env.SWEEP_SEC ?? 60);
const VARIANT_EVERY = Number(process.env.VARIANT_EVERY ?? 5);
Expand Down Expand Up @@ -352,6 +353,25 @@ async function sweep(iteration: number): Promise<void> {
(e) => noteHeartbeat(false, e),
);

// Broadcast the fresh aggregate to Vercel Blob so the site can read
// it from the CDN edge and stop fanning out ~150 concurrent Redis
// GETs per homepage render. See worker/publish-blob.ts for the full
// rationale. No-op when BLOB_READ_WRITE_TOKEN is unset (staged rollout).
if (process.env.BLOB_READ_WRITE_TOKEN) {
const blobStart = Date.now();
const result = await publishAggregateBlob(specs);
const elapsedSec = ((Date.now() - blobStart) / 1000).toFixed(1);
if (result.ok) {
console.log(
`[worker] blob published in ${elapsedSec}s (${result.bytes} bytes, ${result.liveCount}/${result.total} live, revalidated=${result.revalidated})`,
);
} else {
console.warn(
`[worker] blob publish failed in ${elapsedSec}s: ${result.error}`,
);
}
}

// Cohort snapshots used by the hub pages and the search dialog. Each
// builder hits Prom directly (via the in-network http://ocb-prom:9090
// URL), so they don't add load on the public reverse proxy. Failures
Expand Down
Loading
Loading