From 9fba4d3a6b5e8d05dd6af2062bbca505c4010870 Mon Sep 17 00:00:00 2001 From: Simon KP Date: Tue, 24 Feb 2026 23:55:11 +1100 Subject: [PATCH] fix(analytics): use IN subquery instead of innerJoin to avoid Drizzle table ref conflict --- keeperhub/lib/analytics/queries.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/keeperhub/lib/analytics/queries.ts b/keeperhub/lib/analytics/queries.ts index 57ebde47..9d1a85cc 100644 --- a/keeperhub/lib/analytics/queries.ts +++ b/keeperhub/lib/analytics/queries.ts @@ -660,6 +660,17 @@ async function fetchWorkflowRuns( conditions.push(lt(workflowExecutions.startedAt, new Date(cursor))); } + const scopedExecutionIds = db + .select({ id: workflowExecutions.id }) + .from(workflowExecutions) + .where( + and( + sql`${workflowExecutions.workflowId} IN (${orgWorkflowIds})`, + gte(workflowExecutions.startedAt, rangeStart), + lt(workflowExecutions.startedAt, rangeEnd) + ) + ); + const logSummary = db .select({ executionId: workflowExecutionLogs.executionId, @@ -676,15 +687,9 @@ async function fetchWorkflowRuns( )`, }) .from(workflowExecutionLogs) - .innerJoin( - workflowExecutions, - eq(workflowExecutionLogs.executionId, workflowExecutions.id) - ) .where( and( - sql`${workflowExecutions.workflowId} IN (${orgWorkflowIds})`, - gte(workflowExecutions.startedAt, rangeStart), - lt(workflowExecutions.startedAt, rangeEnd), + sql`${workflowExecutionLogs.executionId} IN (${scopedExecutionIds})`, sql`(${logOutputField("gasUsed")} IS NOT NULL OR ${logOutputField("transactionHash")} IS NOT NULL)` ) )