Skip to content

Commit 131f0d3

Browse files
committed
refactor(workflows): resolve the deployed state with one const after the throw
loadDeployedWorkflowState throws first when the active version has no state and Postgres did not withhold one, then picks the cached re-read or the materialization in one expression; behaviour is unchanged.
1 parent 0761363 commit 131f0d3

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

  • apps/sim/lib/workflows/persistence

‎apps/sim/lib/workflows/persistence/utils.ts‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,23 +313,17 @@ export async function loadDeployedWorkflowState(
313313
throw new NoActiveDeploymentError(workflowId)
314314
}
315315

316-
let deployedState: DeployedWorkflowData
317-
if (active.id === cachedVersionId && active.state == null) {
318-
// Served from the cache, or re-read by id if the entry was evicted since the hint.
319-
deployedState = await loadWorkflowDeploymentVersionState(
320-
workflowId,
321-
active.id,
322-
providedWorkspaceId
323-
)
324-
} else if (!active.state) {
325-
throw new NoActiveDeploymentError(workflowId)
326-
} else {
327-
deployedState = await materializeDeploymentState(
328-
workflowId,
329-
active,
330-
await resolveWorkspaceId(workflowId, providedWorkspaceId)
331-
)
332-
}
316+
/** Postgres withheld the state this process already caches for the active version. */
317+
const withheld = active.id === cachedVersionId && active.state == null
318+
if (!withheld && !active.state) throw new NoActiveDeploymentError(workflowId)
319+
const deployedState = withheld
320+
? // Served from the cache, or re-read by id if the entry was evicted since the hint.
321+
await loadWorkflowDeploymentVersionState(workflowId, active.id, providedWorkspaceId)
322+
: await materializeDeploymentState(
323+
workflowId,
324+
active,
325+
await resolveWorkspaceId(workflowId, providedWorkspaceId)
326+
)
333327
cachedVersionByWorkflow.set(workflowId, active.id)
334328
return deployedState
335329
} catch (error) {

0 commit comments

Comments
 (0)