remove-sessions-script
John McLear 2016-03-24 14:29:55 +00:00
parent f725e36523
commit 7001b3b0c7
1 changed files with 27 additions and 11 deletions

View File

@ -10,6 +10,9 @@ var db, settings, keys, values;
var npm = require("../src/node_modules/npm"); var npm = require("../src/node_modules/npm");
var async = require("../src/node_modules/async"); var async = require("../src/node_modules/async");
// Setup a removal count
var removalCount = 0;
async.series([ async.series([
//load npm //load npm
function(callback) { function(callback) {
@ -36,12 +39,17 @@ async.series([
{ {
values = {}; values = {};
async.eachSeries(keys, function(key, cb){ async.eachSeries(keys, function(key, cb){
// only get main pad data not any revisions
if(key.indexOf(":revs") === -1){
db.db.get(key, function(err, value){ db.db.get(key, function(err, value){
// console.log("err", err); // console.log("get value", key, value);
// console.log("value", key, value);
values[key] = value; values[key] = value;
cb(); cb();
}); });
}else{
cb();
}
}, function(){ }, function(){
callback(); callback();
}); });
@ -49,11 +57,16 @@ async.series([
// Removing all old pad data record // Removing all old pad data record
function (callback){ function (callback){
async.each(keys, function(key, cb){ async.each(keys, function(key, cb){
if(key.indexOf(":revs") !== -1){
console.log("Removing", key); console.log("Removing", key);
db.db.remove(key, function(err){ db.db.remove(key, function(err){
removalCount++;
if(err) console.log("err", err); if(err) console.log("err", err);
cb(); cb();
}); });
}else{
cb();
}
}, function(){ }, function(){
callback(); callback();
}); });
@ -61,8 +74,11 @@ async.series([
// Add latest data back in for a pad // Add latest data back in for a pad
function (callback){ function (callback){
async.eachSeries(keys, function(key, cb){ async.eachSeries(keys, function(key, cb){
console.log("Adding data back in for", key); var sauce = values[key];
if(key.indexOf(":revs") === -1){
// console.log("Adding data back in for", key, sauce);
db.db.set(key, values[key]); db.db.set(key, values[key]);
}
cb(); cb();
}, function(){ }, function(){
callback(); callback();
@ -72,7 +88,7 @@ async.series([
{ {
if(err) throw err; if(err) throw err;
else{ else{
console.log("finished"); console.log("finished, total database records removed "+removalCount);
process.exit(0); process.exit(0);
} }
}); });