Skip to content
Merged
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
8 changes: 7 additions & 1 deletion packages/app/src/app/api/v1/benchmarks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ const getCachedBenchmarks = cachedQuery(
{ blobOnly: true },
);

const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/u;

export async function GET(request: NextRequest) {
const params = request.nextUrl.searchParams;
const model = params.get('model') ?? '';
const date = params.get('date') ?? undefined;
// Reject anything that isn't an ISO YYYY-MM-DD — otherwise postgres-js will
// coerce `${date}::date` via `new Date(date)`, which on garbage produces NaN
// and throws `Invalid time value` from toISOString → opaque 500.
const rawDate = params.get('date');
const date = rawDate && ISO_DATE_RE.test(rawDate) ? rawDate : undefined;
const exact = params.get('exact') === 'true';
const dbModelKeys = DISPLAY_MODEL_TO_DB[model];
if (!dbModelKeys || dbModelKeys.length === 0) {
Expand Down
8 changes: 7 additions & 1 deletion packages/app/src/hooks/api/use-benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ export function benchmarkQueryOptions(
enabled = true,
exact?: boolean,
) {
// 'latest' is only a queryKey marker meaning "no specific date" — must NOT
// be sent to the API as a date filter (postgres-js coerces `${date}::date`
// params via `new Date(date)`, which on 'latest' produces NaN and throws
// `Invalid time value` from toISOString → 500 to the client).
const dateForFetch = date === 'latest' ? undefined : date;
return {
queryKey: ['benchmarks', model, date, exact ? 'exact' : 'latest'] as const,
queryFn: ({ signal }: { signal: AbortSignal }) => fetchBenchmarks(model, date, exact, signal),
queryFn: ({ signal }: { signal: AbortSignal }) =>
fetchBenchmarks(model, dateForFetch, exact, signal),
enabled: enabled && Boolean(model),
};
}
Expand Down
Loading