-
Notifications
You must be signed in to change notification settings - Fork 3.3k
improvement(performance): remove writes to workflow updated_at on position updates for blocks, edges, & subflows #1531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ition updates for blocks, edges, & subflows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR implements a targeted performance optimization to reduce database lock contention in workflow operations. The change modifies the database transaction logic in `apps/sim/socket-server/database/operations.ts` to conditionally update the workflow's `updated_at` timestamp based on the operation type.What Changed:
Previously, every workflow operation - including high-frequency position updates for blocks, edges, and subflows - would immediately update the workflow record's updated_at timestamp at the start of each database transaction. This caused multiple concurrent operations to contend for locks on the same workflow record, resulting in an average 200ms update time.
The solution introduces a conditional check: if (op !== 'update-position') before updating the workflow timestamp. This means position updates (which are cosmetic changes that don't affect workflow logic) no longer trigger timestamp updates, while all other meaningful operations continue to update the timestamp as expected.
How It Integrates:
This change fits into the workflow management system's broader architecture where the updateLastSaved function (shown in the context) handles client-side state persistence, while this database operation handles server-side persistence. The optimization specifically targets the server-side database layer to reduce contention without affecting the client-side workflow state management or the overall user experience.
The change also removes debug logging for position updates and reorders the transaction flow to handle operations before timestamp updates, creating a cleaner and more performant execution path.
PR Description Notes:
- Minor typo: "previosuly" should be "previously"
- Minor typo: "wrofklow" should be "workflow"
- Minor typo: "int he" should be "in the"
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| apps/sim/socket-server/database/operations.ts | 4/5 | Adds conditional logic to skip workflow timestamp updates for position-only operations, reducing database lock contention |
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it addresses a clear performance bottleneck without breaking existing functionality
- Score reflects a well-targeted optimization that maintains data consistency while improving performance through reduced lock contention
- The single file change is straightforward and the conditional logic is easy to understand and maintain
Sequence Diagram
sequenceDiagram
participant User
participant SocketServer as Socket Server
participant DB as Database
participant WorkflowTable as workflow table
participant BlocksTable as workflow_blocks table
User->>SocketServer: "Send position update operation"
SocketServer->>SocketServer: "Parse operation (target: block, op: update-position)"
SocketServer->>DB: "Start transaction"
DB->>SocketServer: "Transaction started"
SocketServer->>SocketServer: "handleBlockOperationTx()"
SocketServer->>BlocksTable: "UPDATE workflow_blocks SET positionX, positionY, updatedAt"
BlocksTable->>SocketServer: "Position updated"
SocketServer->>SocketServer: "Check: op !== 'update-position'"
Note over SocketServer: Skip workflow.updatedAt update for position changes
SocketServer->>DB: "Commit transaction"
DB->>SocketServer: "Transaction committed"
SocketServer->>User: "Position update complete"
User->>SocketServer: "Send non-position operation (e.g., add block)"
SocketServer->>SocketServer: "Parse operation (target: block, op: add)"
SocketServer->>DB: "Start transaction"
DB->>SocketServer: "Transaction started"
SocketServer->>SocketServer: "handleBlockOperationTx()"
SocketServer->>BlocksTable: "INSERT new block"
BlocksTable->>SocketServer: "Block inserted"
SocketServer->>SocketServer: "Check: op !== 'update-position'"
Note over SocketServer: Update workflow.updatedAt for non-position changes
SocketServer->>WorkflowTable: "UPDATE workflow SET updatedAt"
WorkflowTable->>SocketServer: "Workflow timestamp updated"
SocketServer->>DB: "Commit transaction"
DB->>SocketServer: "Transaction committed"
SocketServer->>User: "Operation complete"
1 file reviewed, no comments
Summary
remove writes to workflow updated_at on position updates for blocks, edges, & subflows
previosuly, every position update or any operation for that matter updated the workflow record int he wrofklow table
for the logs, this was the pattern before
Type of Change
Testing
Manually
Checklist