mirror of
https://github.com/praveentcom/openproxy.git
synced 2026-02-12 14:02:46 +00:00
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.
This commit is contained in:
@@ -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
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user