mirror of
https://github.com/praveentcom/openproxy.git
synced 2026-07-26 05:40:57 +02: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 model) as unique_models,
|
||||||
COUNT(DISTINCT client_ip) as unique_clients
|
COUNT(DISTINCT client_ip) as unique_clients
|
||||||
FROM ${validatedTableName}
|
FROM ${validatedTableName}
|
||||||
WHERE timestamp >= NOW() - INTERVAL '$1 hours'
|
WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1
|
||||||
`;
|
`;
|
||||||
const summaryResult = await client.query(summaryQuery, [hours]);
|
const summaryResult = await client.query(summaryQuery, [hours]);
|
||||||
const summary = summaryResult.rows[0];
|
const summary = summaryResult.rows[0];
|
||||||
@@ -50,7 +50,7 @@ export async function GET(request: NextRequest) {
|
|||||||
client_ip,
|
client_ip,
|
||||||
stream
|
stream
|
||||||
FROM ${validatedTableName}
|
FROM ${validatedTableName}
|
||||||
WHERE timestamp >= NOW() - INTERVAL '$1 hours'
|
WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1
|
||||||
ORDER BY timestamp DESC
|
ORDER BY timestamp DESC
|
||||||
LIMIT $2
|
LIMIT $2
|
||||||
`;
|
`;
|
||||||
@@ -66,7 +66,7 @@ export async function GET(request: NextRequest) {
|
|||||||
SUM(total_cost) as total_cost,
|
SUM(total_cost) as total_cost,
|
||||||
AVG(response_time) as avg_response_time
|
AVG(response_time) as avg_response_time
|
||||||
FROM ${validatedTableName}
|
FROM ${validatedTableName}
|
||||||
WHERE timestamp >= NOW() - INTERVAL '$1 hours'
|
WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1
|
||||||
GROUP BY model
|
GROUP BY model
|
||||||
ORDER BY request_count DESC
|
ORDER BY request_count DESC
|
||||||
`;
|
`;
|
||||||
@@ -82,7 +82,7 @@ export async function GET(request: NextRequest) {
|
|||||||
SUM(total_cost) as cost,
|
SUM(total_cost) as cost,
|
||||||
AVG(response_time) as avg_response_time
|
AVG(response_time) as avg_response_time
|
||||||
FROM ${validatedTableName}
|
FROM ${validatedTableName}
|
||||||
WHERE timestamp >= NOW() - INTERVAL '$1 hours'
|
WHERE timestamp >= NOW() - INTERVAL '1 hour' * $1
|
||||||
GROUP BY hour
|
GROUP BY hour
|
||||||
ORDER BY hour ASC
|
ORDER BY hour ASC
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user