Skip to content

Commit 5517963

Browse files
committed
fix dashboard
1 parent 72a3a89 commit 5517963

File tree

2 files changed

+10
-65
lines changed

2 files changed

+10
-65
lines changed

apps/sim/app/api/logs/stats/route.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ export async function GET(request: NextRequest) {
9999

100100
const totalMs = Math.max(1, endTime.getTime() - startTime.getTime())
101101
const segmentMs = Math.max(60000, Math.floor(totalMs / params.segmentCount))
102+
const startTimeIso = startTime.toISOString()
102103

103104
const statsQuery = await db
104105
.select({
105106
workflowId: workflowExecutionLogs.workflowId,
106107
workflowName: workflow.name,
107108
segmentIndex:
108-
sql<number>`FLOOR(EXTRACT(EPOCH FROM (${workflowExecutionLogs.startedAt} - ${startTime}::timestamp)) * 1000 / ${segmentMs})`.as(
109+
sql<number>`FLOOR(EXTRACT(EPOCH FROM (${workflowExecutionLogs.startedAt} - ${startTimeIso}::timestamp)) * 1000 / ${segmentMs})`.as(
109110
'segment_index'
110111
),
111112
totalExecutions: sql<number>`COUNT(*)`.as('total_executions'),
@@ -129,12 +130,7 @@ export async function GET(request: NextRequest) {
129130
)
130131
)
131132
.where(whereCondition)
132-
.groupBy(
133-
workflowExecutionLogs.workflowId,
134-
workflow.name,
135-
sql`FLOOR(EXTRACT(EPOCH FROM (${workflowExecutionLogs.startedAt} - ${startTime}::timestamp)) * 1000 / ${segmentMs})`
136-
)
137-
.orderBy(workflowExecutionLogs.workflowId, sql`segment_index`)
133+
.groupBy(sql`1, 2, 3`)
138134

139135
const workflowMap = new Map<
140136
string,

apps/sim/hooks/queries/logs.ts

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -154,68 +154,18 @@ export function useLogDetail(logId: string | undefined) {
154154
})
155155
}
156156

157-
interface DashboardFilters {
158-
timeRange: TimeRange
159-
startDate?: string
160-
endDate?: string
161-
level: string
162-
workflowIds: string[]
163-
folderIds: string[]
164-
triggers: string[]
165-
searchQuery: string
166-
segmentCount?: number
167-
}
168-
169157
/**
170-
* Fetches aggregated dashboard statistics from the server.
171-
* Uses SQL aggregation for efficient computation without row limits.
158+
* Fetches dashboard stats from the server-side aggregation endpoint.
159+
* Uses SQL aggregation for efficient computation without arbitrary limits.
172160
*/
173161
async function fetchDashboardStats(
174162
workspaceId: string,
175-
filters: DashboardFilters
163+
filters: Omit<LogFilters, 'limit'>
176164
): Promise<DashboardStatsResponse> {
177165
const params = new URLSearchParams()
178-
179166
params.set('workspaceId', workspaceId)
180167

181-
if (filters.segmentCount) {
182-
params.set('segmentCount', filters.segmentCount.toString())
183-
}
184-
185-
if (filters.level !== 'all') {
186-
params.set('level', filters.level)
187-
}
188-
189-
if (filters.triggers.length > 0) {
190-
params.set('triggers', filters.triggers.join(','))
191-
}
192-
193-
if (filters.workflowIds.length > 0) {
194-
params.set('workflowIds', filters.workflowIds.join(','))
195-
}
196-
197-
if (filters.folderIds.length > 0) {
198-
params.set('folderIds', filters.folderIds.join(','))
199-
}
200-
201-
const startDate = getStartDateFromTimeRange(filters.timeRange, filters.startDate)
202-
if (startDate) {
203-
params.set('startDate', startDate.toISOString())
204-
}
205-
206-
const endDate = getEndDateFromTimeRange(filters.timeRange, filters.endDate)
207-
if (endDate) {
208-
params.set('endDate', endDate.toISOString())
209-
}
210-
211-
if (filters.searchQuery.trim()) {
212-
const parsedQuery = parseQuery(filters.searchQuery.trim())
213-
const searchParams = queryToApiParams(parsedQuery)
214-
215-
for (const [key, value] of Object.entries(searchParams)) {
216-
params.set(key, value)
217-
}
218-
}
168+
applyFilterParams(params, filters)
219169

220170
const response = await fetch(`/api/logs/stats?${params.toString()}`)
221171

@@ -232,13 +182,12 @@ interface UseDashboardStatsOptions {
232182
}
233183

234184
/**
235-
* Hook for fetching aggregated dashboard statistics.
236-
* Uses server-side SQL aggregation for efficient computation
237-
* without any row limits - all matching logs are included in the stats.
185+
* Hook for fetching dashboard stats using server-side aggregation.
186+
* No arbitrary limits - uses SQL aggregation for accurate metrics.
238187
*/
239188
export function useDashboardStats(
240189
workspaceId: string | undefined,
241-
filters: DashboardFilters,
190+
filters: Omit<LogFilters, 'limit'>,
242191
options?: UseDashboardStatsOptions
243192
) {
244193
return useQuery({

0 commit comments

Comments
 (0)