Skip to content

Commit 0b2be9e

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 a2ce60c commit 0b2be9e

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
@@ -38,11 +38,11 @@ async function eligibleOrgForWorkspace(
3838
): Promise<string | null> {
3939
const ws = await getWorkspaceWithOwner(workspaceId, { includeArchived: true })
4040
if (!ws?.organizationId) return null
41-
if (!(await isFeatureEnabled('deploy-as-block', { userId, orgId: ws.organizationId }))) {
42-
return null
43-
}
44-
if (!(await isOrganizationOnEnterprisePlan(ws.organizationId))) return null
45-
return ws.organizationId
41+
const [flagEnabled, onEnterprisePlan] = await Promise.all([
42+
isFeatureEnabled('deploy-as-block', { userId, orgId: ws.organizationId }),
43+
isOrganizationOnEnterprisePlan(ws.organizationId),
44+
])
45+
return flagEnabled && onEnterprisePlan ? ws.organizationId : null
4646
}
4747

4848
/**

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
@@ -810,22 +826,14 @@ async function executeWorkflowCoreImpl(
810826
allowLargeValueWorkflowScope,
811827
})
812828

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

0 commit comments

Comments
 (0)