From d810f67f4ac158ced0fd1931e7c669aeb7aa7d57 Mon Sep 17 00:00:00 2001 From: wendybujalski Date: Mon, 5 Jan 2026 17:40:36 -0500 Subject: [PATCH] fix(web) - batch webworker writing of deployment atoms How does this PR change the system? Changes the webworker to batch the writing of deployment atoms to avoid having the write fail if it attempts to write too many atoms at once. This fixes a bug where the frontend would not properly load components in the AddComponentModal. Out of Scope: We will want to batch the sending of the patch batch in Edda for deployment MVs as well. How was it tested? Lots of manual testing until it worked! Does it require a docs change? No --- app/web/src/workers/webworker.ts | 53 ++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/app/web/src/workers/webworker.ts b/app/web/src/workers/webworker.ts index 345ee4d78b..6b6bda68bd 100644 --- a/app/web/src/workers/webworker.ts +++ b/app/web/src/workers/webworker.ts @@ -2664,27 +2664,42 @@ const vanaheim = async ( }; const writeDeploymentAtoms = async (db: Database, atoms: AtomWithData[]) => { - const bind: Array = []; - const placeholders: string[] = []; - atoms.forEach((atom) => { - bind.push( - atom.kind, - atom.checksum, - atom.id, - encodeDocumentForDB(atom.data), - ); - placeholders.push("(?, ?, ?, ?)"); - }); + const writeOneBatchOfDeploymentAtoms = async (batch: AtomWithData[]) => { + const bind: Array = []; + const placeholders: string[] = []; + batch.forEach((atom) => { + bind.push( + atom.kind, + atom.checksum, + atom.id, + encodeDocumentForDB(atom.data), + ); + placeholders.push("(?, ?, ?, ?)"); + }); - const sql = `insert into global_atoms - (kind, checksum, args, data) - VALUES - ${placeholders.join(",")} - ON CONFLICT (kind, args) - DO UPDATE SET checksum=excluded.checksum, data=excluded.data; - `; + const sql = `insert into global_atoms + (kind, checksum, args, data) + VALUES + ${placeholders.join(",")} + ON CONFLICT (kind, args) + DO UPDATE SET checksum=excluded.checksum, data=excluded.data; + `; + + await dbWrite(db, { sql, bind }); + }; - await dbWrite(db, { sql, bind }); + // This determines the maximum amount of atoms per write batch + const CHUNK_SIZE = 2000; + + for (let i = 0; i < atoms.length; i += CHUNK_SIZE) { + const chunk = atoms.slice(i, i + CHUNK_SIZE); + await writeOneBatchOfDeploymentAtoms(chunk); + } + + // After writing the given atoms, bust the deployment cache for each of them + atoms.forEach((atom) => { + bustDeployment(atom.kind as GlobalEntity, atom.id); + }); }; const _niflheim = async (