Skip to content

Instantly share code, notes, and snippets.

@char101
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save char101/501566ff853797678442 to your computer and use it in GitHub Desktop.
Save char101/501566ff853797678442 to your computer and use it in GitHub Desktop.
Purge post from nodebb redis db
"use strict";
global.env = process.env.NODE_ENV || 'production';
var nconf = require('nconf'),
async = require('async');
nconf.file({file: "config.json"})
var db = require('./src/database');
db.init();
function deletePost(pid) {
console.log("Removing post " + pid);
async.series([
function(next) {
db.client.keys("categories:recent_posts:cid:*", function(err, keys) {
keys.forEach(function(key) {
db.sortedSetRemove(key, pid);
});
});
next(null);
},
function(next) { db.searchRemove("post", pid, next); },
function(next) { db.sortedSetRemove("posts:pid", pid, next); },
function(next) { db.delete("post:" + pid, next); },
]);
}
function deleteNotification(nid) {
console.log("Removing notification " + nid);
async.series([
function(next) { db.delete("notifications:" + nid, next); },
function(next) { db.setRemove("notifications", nid, next); }
]);
}
function deleteTopic(tid, next) {
console.log("Removing topic " + tid);
async.series([
function(next) {
db.client.keys("post:*", function(err, keys) {
keys.forEach(function(key) {
db.client.hget(key, "tid", function(err, postTid) {
if (postTid == tid) deletePost(key.split(':')[1]);
});
});
});
next(null);
},
function(next) {
db.client.keys("notifications:*", function(err, keys) {
keys.forEach(function(key) {
db.client.hget(key, "uniqueId", function(err, uniqueId) {
if (uniqueId == ("topic:" + tid)) deleteNotification(key.split(':')[1]);
});
});
});
next(null);
},
function(next) {
db.client.keys("categories:*:tid", function(err, keys) {
keys.forEach(function(key) {
db.sortedSetRemove(key, tid);
});
});
next(null);
},
function(next) { db.searchRemove("topic", tid, next); },
function(next) { db.sortedSetRemove("topics:views", tid, next); },
function(next) { db.sortedSetRemove("topics:posts", tid, next); },
function(next) { db.sortedSetRemove("topics:recent", tid, next); },
function(next) { db.sortedSetRemove("topics:tid", tid, next); },
function(next) { db.delete("tid:" + tid + ":followers", next); },
function(next) { db.delete("tid:" + tid + ":read_by_uid", next); },
function(next) { db.delete("topic:" + tid, next); },
], function(err, result) {
if (next) next(err, result);
});
}
async.series([
function(next) { deleteTopic(1, next); },
function(next) { deleteTopic(2, next); },
function(next) { deleteTopic(3, next); },
], function(err, result) {
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment