Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.