mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
pad.js: fix freeze on pad deletion when it has many revisions
This commit is contained in:
parent
09ddfb9e20
commit
53003d4471
2 changed files with 39 additions and 6 deletions
|
@ -16,6 +16,7 @@ var readOnlyManager = require("./ReadOnlyManager");
|
||||||
var crypto = require("crypto");
|
var crypto = require("crypto");
|
||||||
var randomString = require("../utils/randomstring");
|
var randomString = require("../utils/randomstring");
|
||||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
var promises = require('../utils/promises')
|
||||||
|
|
||||||
// serialization/deserialization attributes
|
// serialization/deserialization attributes
|
||||||
var attributeBlackList = ["id"];
|
var attributeBlackList = ["id"];
|
||||||
|
@ -482,14 +483,14 @@ Pad.prototype.remove = async function remove() {
|
||||||
db.remove("readonly2pad:" + readonlyID);
|
db.remove("readonly2pad:" + readonlyID);
|
||||||
|
|
||||||
// delete all chat messages
|
// delete all chat messages
|
||||||
for (let i = 0, n = this.chatHead; i <= n; ++i) {
|
promises.timesLimit(this.chatHead + 1, 500, function (i) {
|
||||||
db.remove("pad:" + padID + ":chat:" + i);
|
return db.remove("pad:" + padID + ":chat:" + i);
|
||||||
}
|
})
|
||||||
|
|
||||||
// delete all revisions
|
// delete all revisions
|
||||||
for (let i = 0, n = this.head; i <= n; ++i) {
|
promises.timesLimit(this.head + 1, 500, function (i) {
|
||||||
db.remove("pad:" + padID + ":revs:" + i);
|
return db.remove("pad:" + padID + ":revs:" + i);
|
||||||
}
|
})
|
||||||
|
|
||||||
// remove pad from all authors who contributed
|
// remove pad from all authors who contributed
|
||||||
this.getAllAuthors().forEach(authorID => {
|
this.getAllAuthors().forEach(authorID => {
|
||||||
|
|
32
src/node/utils/promises.js
Normal file
32
src/node/utils/promises.js
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue