@@ -73,30 +73,59 @@ export async function GET(request: NextRequest) {
7373 const { searchParams } = new URL ( request . url )
7474 const params = QueryParamsSchema . parse ( Object . fromEntries ( searchParams . entries ( ) ) )
7575
76+ // Conditionally select columns based on detail level to optimize performance
77+ const selectColumns =
78+ params . details === 'full'
79+ ? {
80+ id : workflowExecutionLogs . id ,
81+ workflowId : workflowExecutionLogs . workflowId ,
82+ executionId : workflowExecutionLogs . executionId ,
83+ stateSnapshotId : workflowExecutionLogs . stateSnapshotId ,
84+ level : workflowExecutionLogs . level ,
85+ trigger : workflowExecutionLogs . trigger ,
86+ startedAt : workflowExecutionLogs . startedAt ,
87+ endedAt : workflowExecutionLogs . endedAt ,
88+ totalDurationMs : workflowExecutionLogs . totalDurationMs ,
89+ executionData : workflowExecutionLogs . executionData , // Large field - only in full mode
90+ cost : workflowExecutionLogs . cost ,
91+ files : workflowExecutionLogs . files , // Large field - only in full mode
92+ createdAt : workflowExecutionLogs . createdAt ,
93+ workflowName : workflow . name ,
94+ workflowDescription : workflow . description ,
95+ workflowColor : workflow . color ,
96+ workflowFolderId : workflow . folderId ,
97+ workflowUserId : workflow . userId ,
98+ workflowWorkspaceId : workflow . workspaceId ,
99+ workflowCreatedAt : workflow . createdAt ,
100+ workflowUpdatedAt : workflow . updatedAt ,
101+ }
102+ : {
103+ // Basic mode - exclude large fields for better performance
104+ id : workflowExecutionLogs . id ,
105+ workflowId : workflowExecutionLogs . workflowId ,
106+ executionId : workflowExecutionLogs . executionId ,
107+ stateSnapshotId : workflowExecutionLogs . stateSnapshotId ,
108+ level : workflowExecutionLogs . level ,
109+ trigger : workflowExecutionLogs . trigger ,
110+ startedAt : workflowExecutionLogs . startedAt ,
111+ endedAt : workflowExecutionLogs . endedAt ,
112+ totalDurationMs : workflowExecutionLogs . totalDurationMs ,
113+ executionData : sql < null > `NULL` , // Exclude large execution data in basic mode
114+ cost : workflowExecutionLogs . cost ,
115+ files : sql < null > `NULL` , // Exclude files in basic mode
116+ createdAt : workflowExecutionLogs . createdAt ,
117+ workflowName : workflow . name ,
118+ workflowDescription : workflow . description ,
119+ workflowColor : workflow . color ,
120+ workflowFolderId : workflow . folderId ,
121+ workflowUserId : workflow . userId ,
122+ workflowWorkspaceId : workflow . workspaceId ,
123+ workflowCreatedAt : workflow . createdAt ,
124+ workflowUpdatedAt : workflow . updatedAt ,
125+ }
126+
76127 const baseQuery = db
77- . select ( {
78- id : workflowExecutionLogs . id ,
79- workflowId : workflowExecutionLogs . workflowId ,
80- executionId : workflowExecutionLogs . executionId ,
81- stateSnapshotId : workflowExecutionLogs . stateSnapshotId ,
82- level : workflowExecutionLogs . level ,
83- trigger : workflowExecutionLogs . trigger ,
84- startedAt : workflowExecutionLogs . startedAt ,
85- endedAt : workflowExecutionLogs . endedAt ,
86- totalDurationMs : workflowExecutionLogs . totalDurationMs ,
87- executionData : workflowExecutionLogs . executionData ,
88- cost : workflowExecutionLogs . cost ,
89- files : workflowExecutionLogs . files ,
90- createdAt : workflowExecutionLogs . createdAt ,
91- workflowName : workflow . name ,
92- workflowDescription : workflow . description ,
93- workflowColor : workflow . color ,
94- workflowFolderId : workflow . folderId ,
95- workflowUserId : workflow . userId ,
96- workflowWorkspaceId : workflow . workspaceId ,
97- workflowCreatedAt : workflow . createdAt ,
98- workflowUpdatedAt : workflow . updatedAt ,
99- } )
128+ . select ( selectColumns )
100129 . from ( workflowExecutionLogs )
101130 . innerJoin ( workflow , eq ( workflowExecutionLogs . workflowId , workflow . id ) )
102131 . innerJoin (
@@ -276,18 +305,24 @@ export async function GET(request: NextRequest) {
276305 const enhancedLogs = logs . map ( ( log ) => {
277306 const blockExecutions = blockExecutionsByExecution [ log . executionId ] || [ ]
278307
279- // Use stored trace spans if available, otherwise create from block executions
280- const storedTraceSpans = ( log . executionData as any ) ?. traceSpans
281- const traceSpans =
282- storedTraceSpans && Array . isArray ( storedTraceSpans ) && storedTraceSpans . length > 0
283- ? storedTraceSpans
284- : createTraceSpans ( blockExecutions )
285-
286- // Prefer stored cost JSON; otherwise synthesize from blocks
287- const costSummary =
288- log . cost && Object . keys ( log . cost as any ) . length > 0
289- ? ( log . cost as any )
290- : extractCostSummary ( blockExecutions )
308+ // Only process trace spans and detailed cost in full mode
309+ let traceSpans = [ ]
310+ let costSummary = ( log . cost as any ) || { total : 0 }
311+
312+ if ( params . details === 'full' && log . executionData ) {
313+ // Use stored trace spans if available, otherwise create from block executions
314+ const storedTraceSpans = ( log . executionData as any ) ?. traceSpans
315+ traceSpans =
316+ storedTraceSpans && Array . isArray ( storedTraceSpans ) && storedTraceSpans . length > 0
317+ ? storedTraceSpans
318+ : createTraceSpans ( blockExecutions )
319+
320+ // Prefer stored cost JSON; otherwise synthesize from blocks
321+ costSummary =
322+ log . cost && Object . keys ( log . cost as any ) . length > 0
323+ ? ( log . cost as any )
324+ : extractCostSummary ( blockExecutions )
325+ }
291326
292327 const workflowSummary = {
293328 id : log . workflowId ,
0 commit comments