Pad: Limit DB concurrency when copying a pad
parent
8442e002f9
commit
096379e6f9
|
@ -35,6 +35,8 @@
|
||||||
* Docker now uses the new `/health` endpoint for health checks, which avoids
|
* Docker now uses the new `/health` endpoint for health checks, which avoids
|
||||||
issues when authentication is enabled. It also avoids the unnecessary creation
|
issues when authentication is enabled. It also avoids the unnecessary creation
|
||||||
of database records for managing browser sessions.
|
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
|
#### For plugin authors
|
||||||
|
|
||||||
|
|
|
@ -383,13 +383,14 @@ class Pad {
|
||||||
await db.set(`pad:${destinationID}${keySuffix}`, val);
|
await db.set(`pad:${destinationID}${keySuffix}`, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
await Promise.all((function* () {
|
const promises = (function* () {
|
||||||
yield copyRecord('');
|
yield copyRecord('');
|
||||||
yield* Stream.range(0, this.head + 1).map((i) => copyRecord(`:revs:${i}`));
|
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* Stream.range(0, this.chatHead + 1).map((i) => copyRecord(`:chat:${i}`));
|
||||||
yield this.copyAuthorInfoToDestinationPad(destinationID);
|
yield this.copyAuthorInfoToDestinationPad(destinationID);
|
||||||
if (destGroupID) yield db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1);
|
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)
|
// Initialize the new pad (will update the listAllPads cache)
|
||||||
const dstPad = await padManager.getPad(destinationID, null);
|
const dstPad = await padManager.getPad(destinationID, null);
|
||||||
|
|
Loading…
Reference in New Issue