Skip to content

Instantly share code, notes, and snippets.

@barisusakli
Created October 6, 2017 16:45
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/53ba1a6032e471de78baddd5cc4212a8 to your computer and use it in GitHub Desktop.
Save barisusakli/53ba1a6032e471de78baddd5cc4212a8 to your computer and use it in GitHub Desktop.
undo votes by users with less than x reputation
/*globals require, console, process */
'use strict';
var nconf = require('nconf');
var async = require('async');
nconf.file({
file: 'config.json'
});
nconf.defaults({
base_dir: __dirname,
});
var db = require('./src/database');
db.init(function(err) {
if (err) {
console.log("NodeBB could not connect to your database. Error: " + err.message);
process.exit();
}
undoVotes(function (err) {
if (err) {
console.error(err);
process.exit();
}
console.log('done');
process.exit();
});
});
function undoVotes(callback) {
db.getSortedSetRangeByScore('users:reputation', 0, -1, '-inf', 150, function (err, uids) {
if (err) {
return callback(err);
}
console.log(uids.length + ' users with less than 151 reputation');
async.eachSeries(uids, undoUserDownVotes, callback);
});
}
function undoUserDownVotes(uid, callback) {
var posts = require('./src/posts');
db.getSortedSetRange('uid:' + uid + ':downvote', 0, -1, function (err, pids) {
if (err) {
return callback(err);
}
if (!pids.length) {
//console.log('uid ' + uid + ' does not have any downvotes');
return callback();
}
async.eachSeries(pids, function (pid, next) {
console.log('uid ' + uid + ' unvoting ' + pid);
posts.unvote(pid, uid, next);
}, callback);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment