Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions src/node/db/Pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var readOnlyManager = require("./ReadOnlyManager");
var crypto = require("crypto");
var randomString = require("../utils/randomstring");
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var promises = require('../utils/promises')

// serialization/deserialization attributes
var attributeBlackList = ["id"];
Expand Down Expand Up @@ -482,14 +483,14 @@ Pad.prototype.remove = async function remove() {
db.remove("readonly2pad:" + readonlyID);

// delete all chat messages
for (let i = 0, n = this.chatHead; i <= n; ++i) {
db.remove("pad:" + padID + ":chat:" + i);
}
promises.timesLimit(this.chatHead + 1, 500, function (i) {
return db.remove("pad:" + padID + ":chat:" + i, null);
})

// delete all revisions
for (let i = 0, n = this.head; i <= n; ++i) {
db.remove("pad:" + padID + ":revs:" + i);
}
promises.timesLimit(this.head + 1, 500, function (i) {
return db.remove("pad:" + padID + ":revs:" + i, null);
})

// remove pad from all authors who contributed
this.getAllAuthors().forEach(authorID => {
Expand Down
32 changes: 32 additions & 0 deletions src/node/utils/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Helpers to manipulate promises (like async but for promises).
*/

var timesLimit = function (ltMax, concurrency, promiseCreator) {
var done = 0
var current = 0

function addAnother () {
function _internalRun () {
done++

if (done < ltMax) {
addAnother()
}
}

promiseCreator(current)
.then(_internalRun)
.catch(_internalRun)

current++
}

for (var i = 0; i < concurrency && i < ltMax; i++) {
addAnother()
}
}

module.exports = {
timesLimit: timesLimit
}