From 2ccedc2a0efd6c0d89a935f9f4d62ff87117c98c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 04:21:03 +0000 Subject: [PATCH] Fix SQL INTERVAL syntax bug in metrics API Changed INTERVAL '$1 hours' to INTERVAL '1 hour' * $1 in all queries. The previous syntax didn't properly parameterize the hours value, causing PostgreSQL to treat $1 as a literal string instead of substituting the actual parameter value. This fix ensures the time range filter works correctly for all metric queries. --- dashboard/app/api/metrics/route.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dashboard/app/api/metrics/route.ts b/dashboard/app/api/metrics/route.ts index b8d72be..12533cc 100644 --- a/dashboard/app/api/metrics/route.ts +++ b/dashboard/app/api/metrics/route.ts @@ -30,7 +30,7 @@ export async function GET(request: NextRequest) { COUNT(DISTINCT model) as unique_models, COUNT(DISTINCT client_ip) as unique_clients FROM ${validatedTableName} - WHERE timestamp >= NOW() - INTERVAL '$1 hours' + WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1 `; const summaryResult = await client.query(summaryQuery, [hours]); const summary = summaryResult.rows[0]; @@ -50,7 +50,7 @@ export async function GET(request: NextRequest) { client_ip, stream FROM ${validatedTableName} - WHERE timestamp >= NOW() - INTERVAL '$1 hours' + WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1 ORDER BY timestamp DESC LIMIT $2 `; @@ -66,7 +66,7 @@ export async function GET(request: NextRequest) { SUM(total_cost) as total_cost, AVG(response_time) as avg_response_time FROM ${validatedTableName} - WHERE timestamp >= NOW() - INTERVAL '$1 hours' + WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1 GROUP BY model ORDER BY request_count DESC `; @@ -82,7 +82,7 @@ export async function GET(request: NextRequest) { SUM(total_cost) as cost, AVG(response_time) as avg_response_time FROM ${validatedTableName} - WHERE timestamp >= NOW() - INTERVAL '$1 hours' + WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1 GROUP BY hour ORDER BY hour ASC `;