-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(persistence): chunk block and edge inserts to prevent sql variabl… #3428
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -490,6 +490,8 @@ export async function saveWorkflowToNormalizedTables( | |||||||||||||||||||
| tx.delete(workflowSubflows).where(eq(workflowSubflows.workflowId, workflowId)), | ||||||||||||||||||||
| ]) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const CHUNK_SIZE = 50 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Insert blocks | ||||||||||||||||||||
| if (Object.keys(state.blocks).length > 0) { | ||||||||||||||||||||
| const blockInserts = Object.values(state.blocks).map((block) => ({ | ||||||||||||||||||||
|
|
@@ -512,7 +514,9 @@ export async function saveWorkflowToNormalizedTables( | |||||||||||||||||||
| locked: block.locked ?? false, | ||||||||||||||||||||
| })) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| await tx.insert(workflowBlocks).values(blockInserts) | ||||||||||||||||||||
| for (let i = 0; i < blockInserts.length; i += CHUNK_SIZE) { | ||||||||||||||||||||
| await tx.insert(workflowBlocks).values(blockInserts.slice(i, i + CHUNK_SIZE)) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+517
to
+519
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SQLite hard limit of 999 bound parameters per statement is implicit in the choice of
Suggested change
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Insert edges | ||||||||||||||||||||
|
|
@@ -526,7 +530,9 @@ export async function saveWorkflowToNormalizedTables( | |||||||||||||||||||
| targetHandle: edge.targetHandle || null, | ||||||||||||||||||||
| })) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| await tx.insert(workflowEdges).values(edgeInserts) | ||||||||||||||||||||
| for (let i = 0; i < edgeInserts.length; i += CHUNK_SIZE) { | ||||||||||||||||||||
| await tx.insert(workflowEdges).values(edgeInserts.slice(i, i + CHUNK_SIZE)) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Insert subflows (loops and parallels) | ||||||||||||||||||||
|
|
@@ -553,7 +559,9 @@ export async function saveWorkflowToNormalizedTables( | |||||||||||||||||||
| }) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (subflowInserts.length > 0) { | ||||||||||||||||||||
| await tx.insert(workflowSubflows).values(subflowInserts) | ||||||||||||||||||||
| for (let i = 0; i < subflowInserts.length; i += CHUNK_SIZE) { | ||||||||||||||||||||
| await tx.insert(workflowSubflows).values(subflowInserts.slice(i, i + CHUNK_SIZE)) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
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.
CHUNK_SIZE is defined inside the
db.transactionasync callback, which means it's re-created on every call tosaveWorkflowToNormalizedTables. Since it's a fixed, never-changing value, consider hoisting it to module scope. This makes the intent clearer and avoids unnecessary re-allocation.Place this near the top of the file alongside other module-level constants (e.g., after the logger definition on line 22).
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!