Skip to content

Commit 5846d2a

Browse files
fix(tables): address review — drizzle operators for orphan filter, enabled flag for files query
- dispatcher: replace the `not(and(...)) as SQL` cast in countRunningCells with `or(ne(status,'pending'), isNotNull(executionId))` — De Morgan equivalent, fully type-checked, no cast and no hand-written raw SQL. - workspace-files: add an `enabled` option to useWorkspaceFiles; sim-resource cell now passes the real workspaceId with `enabled` instead of '' so the query cache isn't polluted with an empty-key entry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 99cbfcb commit 5846d2a

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/cells/sim-resource-cell.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export function SimResourceCell({
5050
const { data: knowledgeBases = [] } = useKnowledgeBasesQuery(workspaceId, {
5151
enabled: resourceType === 'knowledge',
5252
})
53-
const { data: files = [] } = useWorkspaceFiles(resourceType === 'file' ? workspaceId : '')
53+
const { data: files = [] } = useWorkspaceFiles(workspaceId, 'active', {
54+
enabled: resourceType === 'file',
55+
})
5456

5557
const workflow =
5658
resourceType === 'workflow' ? workflows.find((w) => w.id === resourceId) : undefined

apps/sim/hooks/queries/workspace-files.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ async function fetchWorkspaceFiles(
9898
/**
9999
* Hook to fetch workspace files
100100
*/
101-
export function useWorkspaceFiles(workspaceId: string, scope: WorkspaceFileQueryScope = 'active') {
101+
export function useWorkspaceFiles(
102+
workspaceId: string,
103+
scope: WorkspaceFileQueryScope = 'active',
104+
options?: { enabled?: boolean }
105+
) {
102106
return useQuery({
103107
queryKey: workspaceFilesKeys.list(workspaceId, scope),
104108
queryFn: ({ signal }) => fetchWorkspaceFiles(workspaceId, scope, signal),
105-
enabled: !!workspaceId,
109+
enabled: !!workspaceId && (options?.enabled ?? true),
106110
staleTime: 30 * 1000, // 30 seconds - files can change frequently
107111
placeholderData: keepPreviousData, // Show cached data immediately
108112
})

apps/sim/lib/table/dispatcher.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { tableRowExecutions, tableRunDispatches, userTableRows } from '@sim/db/s
33
import { createLogger } from '@sim/logger'
44
import { toError } from '@sim/utils/errors'
55
import { generateId } from '@sim/utils/id'
6-
import { and, asc, eq, gt, inArray, isNull, not, type SQL, sql } from 'drizzle-orm'
6+
import { and, asc, eq, gt, inArray, isNotNull, ne, or, type SQL, sql } from 'drizzle-orm'
77
import { getJobQueue } from '@/lib/core/async-jobs/config'
88
import { writeWorkflowGroupState } from '@/lib/table/cell-write'
99
import { appendTableEvent } from '@/lib/table/events'
@@ -208,12 +208,9 @@ export async function countRunningCells(
208208
and(
209209
eq(tableRowExecutions.tableId, tableId),
210210
inArray(tableRowExecutions.status, ['queued', 'running', 'pending']),
211-
not(
212-
and(
213-
eq(tableRowExecutions.status, 'pending'),
214-
isNull(tableRowExecutions.executionId)
215-
) as SQL
216-
)
211+
// Exclude orphan pre-stamps (`pending` + null executionId). De Morgan of
212+
// NOT(pending AND null) — `status` is NOT NULL so `ne` is well-defined.
213+
or(ne(tableRowExecutions.status, 'pending'), isNotNull(tableRowExecutions.executionId))
217214
)
218215
)
219216
.groupBy(tableRowExecutions.rowId)

0 commit comments

Comments
 (0)