Skip to content
Closed
Changes from all commits
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
28 changes: 20 additions & 8 deletions src/hostBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,28 @@ export class HostBridge implements ToastService {
const savepointName = `sp_batch_fallback_${Date.now()}`;
await dbOps.executeQuery(`SAVEPOINT ${savepointName}`);
try {
for (const update of processedUpdates) {
let patch: string | undefined;
let val = update.value;
// Process in chunks to balance IPC overhead and N+1 sequential bottlenecks
const CHUNK_SIZE = 50;
for (let i = 0; i < processedUpdates.length; i += CHUNK_SIZE) {
const chunk = processedUpdates.slice(i, i + CHUNK_SIZE);
const promises = chunk.map(update => {
let patch: string | undefined;
let val = update.value;

if (update.operation === 'json_patch') {
patch = update.value as string;
val = null;
}

if (update.operation === 'json_patch') {
patch = update.value as string;
val = null;
}
return dbOps.updateCell(table, update.rowId, update.column, val, patch);
});

await dbOps.updateCell(table, update.rowId, update.column, val, patch);
// Wait for all in chunk to settle to avoid rolling back while concurrent queries are running
const results = await Promise.allSettled(promises);
const rejected = results.find(r => r.status === 'rejected');
if (rejected) {
throw (rejected as PromiseRejectedResult).reason;
}
}
await dbOps.executeQuery(`RELEASE SAVEPOINT ${savepointName}`);
} catch (err) {
Expand Down
Loading