etherpad-lite/bin/removeOldPadData.js

97 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

/*
2016-03-24 14:32:17 +00:00
This is a debug tool. It removes old pad data from a non-dirty database
It also removes previous pad history so use it carefully.
*/
//get the padID
var padId = process.argv[2];
//initalize the variables
var db, settings, keys, values;
var npm = require("../src/node_modules/npm");
var async = require("../src/node_modules/async");
2016-03-24 14:29:55 +00:00
// Setup a removal count
var removalCount = 0;
async.series([
//load npm
function(callback) {
npm.load({}, function(er) {
callback(er);
})
},
//load modules
function(callback) {
settings = require('../src/node/utils/Settings');
db = require('../src/node/db/DB');
//intallize the database
db.init(callback);
},
//get the session info
function (callback){
db.db.findKeys("pad:*",null, function(err, dbkeys){
keys = dbkeys;
callback();
});
},
function (callback)
{
values = {};
async.eachSeries(keys, function(key, cb){
2016-03-24 14:29:55 +00:00
// only get main pad data not any revisions
if(key.indexOf(":revs") === -1){
db.db.get(key, function(err, value){
// console.log("get value", key, value);
values[key] = value;
cb();
});
}else{
cb();
2016-03-24 14:29:55 +00:00
}
}, function(){
callback();
});
},
// Removing all old pad data record
function (callback){
async.each(keys, function(key, cb){
2016-03-24 14:29:55 +00:00
if(key.indexOf(":revs") !== -1){
console.log("Removing", key);
db.db.remove(key, function(err){
2016-03-24 14:29:55 +00:00
removalCount++;
if(err) console.log("err", err);
cb();
});
}else{
cb();
2016-03-24 14:29:55 +00:00
}
}, function(){
callback();
});
},
// Add latest data back in for a pad
function (callback){
async.eachSeries(keys, function(key, cb){
2016-03-24 14:29:55 +00:00
var sauce = values[key];
if(key.indexOf(":revs") === -1){
// console.log("Adding data back in for", key, sauce);
db.db.set(key, values[key]);
}
cb();
}, function(){
callback();
});
}
], function (err)
{
if(err) throw err;
else{
2016-03-24 14:29:55 +00:00
console.log("finished, total database records removed "+removalCount);
process.exit(0);
}
});