diff --git a/CHANGELOG.md b/CHANGELOG.md index 580e551c..680a5faa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ timeouts with large pads. * Exporting a large pad to `.etherpad` format should be faster thanks to bulk database record fetches. +* When importing an `.etherpad` file, records are now saved to the database in + batches to avoid database timeouts with large pads. #### For plugin authors diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index a028ee12..2c785493 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -105,8 +105,9 @@ exports.setPadRaw = async (padId, r, authorId = '') => { await padDb.close(); } - await Promise.all([ - ...[...data].map(([k, v]) => q.pushAsync(() => db.set(k, v))), - ...[...existingAuthors].map((a) => q.pushAsync(() => authorManager.addPad(a, padId))), - ]); + const writeOps = (function* () { + for (const [k, v] of data) yield db.set(k, v); + for (const a of existingAuthors) yield authorManager.addPad(a, padId); + })(); + for (const op of new Stream(writeOps).batch(100).buffer(99)) await op; };