Skip to content

Commit c64a9fa

Browse files
committed
perf(deploy): parallelize all DB queries in checkNeedsRedeployment
All three queries (active version, normalized data, workflow variables) now run concurrently via Promise.all, saving one DB round trip on the common path.
1 parent 44df76d commit c64a9fa

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

apps/sim/app/api/workflows/utils.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,27 @@ export function createSuccessResponse(data: any) {
3232
* both the /deploy and /status endpoints to ensure consistent results.
3333
*/
3434
export async function checkNeedsRedeployment(workflowId: string): Promise<boolean> {
35-
const [active] = await db
36-
.select({ state: workflowDeploymentVersion.state })
37-
.from(workflowDeploymentVersion)
38-
.where(
39-
and(
40-
eq(workflowDeploymentVersion.workflowId, workflowId),
41-
eq(workflowDeploymentVersion.isActive, true)
35+
const [[active], normalizedData, [workflowRecord]] = await Promise.all([
36+
db
37+
.select({ state: workflowDeploymentVersion.state })
38+
.from(workflowDeploymentVersion)
39+
.where(
40+
and(
41+
eq(workflowDeploymentVersion.workflowId, workflowId),
42+
eq(workflowDeploymentVersion.isActive, true)
43+
)
4244
)
43-
)
44-
.orderBy(desc(workflowDeploymentVersion.createdAt))
45-
.limit(1)
46-
47-
if (!active?.state) return false
48-
49-
const [normalizedData, [workflowRecord]] = await Promise.all([
45+
.orderBy(desc(workflowDeploymentVersion.createdAt))
46+
.limit(1),
5047
loadWorkflowFromNormalizedTables(workflowId),
5148
db
5249
.select({ variables: workflow.variables })
5350
.from(workflow)
5451
.where(eq(workflow.id, workflowId))
5552
.limit(1),
5653
])
57-
if (!normalizedData) return false
54+
55+
if (!active?.state || !normalizedData) return false
5856

5957
const currentState = {
6058
blocks: normalizedData.blocks,

0 commit comments

Comments
 (0)