Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions apps/sim/socket-server/database/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,8 @@ export async function persistWorkflowOperation(workflowId: string, operation: an
try {
const { operation: op, target, payload, timestamp, userId } = operation

// Log high-frequency operations for monitoring
if (op === 'update-position' && Math.random() < 0.01) {
// Log 1% of position updates
logger.debug('Socket DB operation sample:', {
operation: op,
target,
workflowId: `${workflowId.substring(0, 8)}...`,
})
}

await db.transaction(async (tx) => {
// Update the workflow's last modified timestamp first
await tx
.update(workflow)
.set({ updatedAt: new Date(timestamp) })
.where(eq(workflow.id, workflowId))

// Handle different operation types within the transaction
// Handle different operation types within the transaction first
switch (target) {
case 'block':
await handleBlockOperationTx(tx, workflowId, op, payload, userId)
Expand All @@ -202,6 +186,13 @@ export async function persistWorkflowOperation(workflowId: string, operation: an
default:
throw new Error(`Unknown operation target: ${target}`)
}

if (op !== 'update-position') {
await tx
.update(workflow)
.set({ updatedAt: new Date(timestamp) })
.where(eq(workflow.id, workflowId))
}
})

// Log slow operations for monitoring
Expand Down