Skip to content

Instantly share code, notes, and snippets.

@psychobunny

psychobunny/debug.js

Last active Apr 16, 2020
Embed
What would you like to do?
NodeBB patch - Remove OP and replace it with first reply
// paste this in https://github.com/NodeBB/NodeBB/blob/master/src/routes/debug.js
// and then don't forget to remove it!
router.get('/remove-op', function(req, res) {
var db = require('../database'),
async = require('async');
db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {
async.eachLimit(tids, 50, function(tid, next) {
db.getSortedSetRange('tid:' + tid + ':posts', 0, 0, function(err, pid) {
if (err) {
throw new Error(err);
}
pid = pid[0];
db.sortedSetRemove('tid:' + tid + ':posts', pid, function(err) {
if (err) {
throw new Error(err);
}
db.setObjectField('topic:' + tid, 'mainPid', pid, next);
});
});
}, function(err) {
if (err) {
throw new Error(err);
}
res.json({status: true});
});
});
});
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.