Skip to content

Instantly share code, notes, and snippets.

@barisusakli
Last active August 29, 2015 14:05
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 barisusakli/224a7ee8c3be6844687e to your computer and use it in GitHub Desktop.
Save barisusakli/224a7ee8c3be6844687e to your computer and use it in GitHub Desktop.
fix mainPids in sorted sets
router.get('/fixTopics', function(req, res) {
var db = require('../database'),
async = require('async');
db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {
function fixTopic(tid, next) {
topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
if (err) {
return next(err);
}
db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
if (err) {
return next(err);
}
if (!Array.isArray(pids) || !pids.length) {
return next();
}
if (pids.indexOf(mainPid) === -1) {
return next();
}
async.parallel([
function(next) {
db.sortedSetRemove('tid:' + tid + ':posts', mainPid, next);
},
function(next) {
db.sortedSetRemove('tid:' + tid + ':posts:votes', mainPid, next);
}
], next);
});
});
}
async.eachLimit(tids, 10, fixTopic, function(err) {
if (err) {
return res.json(500, err.message);
}
res.json('Done');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment