Skip to content

Commit 04e5bec

Browse files
icecrasher321claude
andcommitted
improvement(executor): parallelize the execution-core serial front
The PII-redaction row read (workspace ⋈ organization) joins the existing state + environment Promise.all instead of running serially after logging start, and eligibleOrgForWorkspace resolves its feature-flag and enterprise-plan reads concurrently after the workspace lookup. Identical results; fewer serial round trips for every execution path, including Trigger.dev workers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 78f665f commit 04e5bec

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

apps/sim/lib/workflows/custom-blocks/operations.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ async function eligibleOrgForWorkspace(
3636
): Promise<string | null> {
3737
const ws = await getWorkspaceWithOwner(workspaceId, { includeArchived: true })
3838
if (!ws?.organizationId) return null
39-
if (!(await isFeatureEnabled('deploy-as-block', { userId, orgId: ws.organizationId }))) {
40-
return null
41-
}
42-
if (!(await isOrganizationOnEnterprisePlan(ws.organizationId))) return null
43-
return ws.organizationId
39+
const [flagEnabled, onEnterprisePlan] = await Promise.all([
40+
isFeatureEnabled('deploy-as-block', { userId, orgId: ws.organizationId }),
41+
isOrganizationOnEnterprisePlan(ws.organizationId),
42+
])
43+
return flagEnabled && onEnterprisePlan ? ws.organizationId : null
4444
}
4545

4646
/**

apps/sim/lib/workflows/executor/execution-core.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,25 @@ async function executeWorkflowCoreImpl(
525525
}
526526
}
527527

528-
const [workflowState, env] = await Promise.all([
528+
/**
529+
* Resolves the org/workspace PII redaction row once for this run; serves both
530+
* the input stage and the block-outputs stage (threaded into the executor).
531+
* Depends only on the workspace id, so it loads alongside the state and env.
532+
*/
533+
const loadPiiRedactionRow = async () => {
534+
const [row] = await db
535+
.select({ orgSettings: organization.dataRetentionSettings })
536+
.from(workspace)
537+
.leftJoin(organization, eq(organization.id, workspace.organizationId))
538+
.where(eq(workspace.id, providedWorkspaceId))
539+
.limit(1)
540+
return row
541+
}
542+
543+
const [workflowState, env, piiRedactionRow] = await Promise.all([
529544
loadWorkflowState(),
530545
getExecutionEnvironment(personalEnvUserId, workspaceEnvUserId, providedWorkspaceId),
546+
loadPiiRedactionRow(),
531547
])
532548

533549
const { blocks, loops, parallels } = workflowState
@@ -808,22 +824,14 @@ async function executeWorkflowCoreImpl(
808824
allowLargeValueWorkflowScope,
809825
})
810826

811-
// Resolve the org/workspace PII redaction policy once; serves both the input
812-
// stage (below) and the block-outputs stage (threaded into the executor).
813-
// Resolved from stored rules UNCONDITIONALLY — deliberately NOT gated on the
814-
// `pii-redaction` feature flag. The flag gates configuration (the settings
815-
// route); a transient/false flag read at execution time would skip masking
816-
// and leak PII (fail-open). Stored rules are only writable by entitled orgs,
817-
// so their presence is the source of truth; absence yields the disabled
818-
// default (one indexed lookup, no masking cost for non-PII orgs).
819-
const [row] = await db
820-
.select({ orgSettings: organization.dataRetentionSettings })
821-
.from(workspace)
822-
.leftJoin(organization, eq(organization.id, workspace.organizationId))
823-
.where(eq(workspace.id, providedWorkspaceId))
824-
.limit(1)
827+
// The policy applies from stored rules UNCONDITIONALLY — deliberately NOT
828+
// gated on the `pii-redaction` feature flag. The flag gates configuration
829+
// (the settings route); a transient/false flag read at execution time would
830+
// skip masking and leak PII (fail-open). Stored rules are only writable by
831+
// entitled orgs, so their presence is the source of truth; absence yields
832+
// the disabled default (one indexed lookup, no masking cost for non-PII orgs).
825833
const piiRedaction: EffectivePiiRedaction = resolveEffectivePiiRedaction({
826-
orgSettings: row?.orgSettings,
834+
orgSettings: piiRedactionRow?.orgSettings,
827835
workspaceId: providedWorkspaceId,
828836
})
829837

0 commit comments

Comments
 (0)