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
22 changes: 21 additions & 1 deletion website/public/sqlite-viewer/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,29 @@ async function updateCellBatch(table, updates) {

db.run('BEGIN TRANSACTION');
try {
const safeTable = table.replace(/"/g, '""');

// Group updates by column to minimize statement preparation overhead
const byColumn = {};
for (const update of updates) {
await updateCell(table, update.rowId, update.column, update.value);
const col = update.column;
if (!byColumn[col]) byColumn[col] = [];
byColumn[col].push(update);
}

for (const column of Object.keys(byColumn)) {
const safeColumn = column.replace(/"/g, '""');
const stmt = db.prepare(`UPDATE "${safeTable}" SET "${safeColumn}" = ? WHERE rowid = ?`);

try {
for (const update of byColumn[column]) {
stmt.run([update.value, update.rowId]);
}
} finally {
stmt.free();
}
}

db.run('COMMIT');
} catch (e) {
db.run('ROLLBACK');
Expand Down
Loading