From 096379e6f9af6929d86781820b1d7d53d730e3a1 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 15 Apr 2022 02:57:43 -0400 Subject: [PATCH] Pad: Limit DB concurrency when copying a pad --- CHANGELOG.md | 2 ++ src/node/db/Pad.js | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bdd41a50..672d5feb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ * Docker now uses the new `/health` endpoint for health checks, which avoids issues when authentication is enabled. It also avoids the unnecessary creation of database records for managing browser sessions. +* When copying a pad, the pad's records are copied in batches to avoid database + timeouts with large pads. #### For plugin authors diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 920d1661f..7cc46cdb8 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -383,13 +383,14 @@ class Pad { await db.set(`pad:${destinationID}${keySuffix}`, val); }; - await Promise.all((function* () { + const promises = (function* () { yield copyRecord(''); yield* Stream.range(0, this.head + 1).map((i) => copyRecord(`:revs:${i}`)); yield* Stream.range(0, this.chatHead + 1).map((i) => copyRecord(`:chat:${i}`)); yield this.copyAuthorInfoToDestinationPad(destinationID); if (destGroupID) yield db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1); - }).call(this)); + }).call(this); + for (const p of new Stream(promises).batch(100).buffer(99)) await p; // Initialize the new pad (will update the listAllPads cache) const dstPad = await padManager.getPad(destinationID, null);