Created
October 6, 2017 16:45
-
-
Save barisusakli/53ba1a6032e471de78baddd5cc4212a8 to your computer and use it in GitHub Desktop.
undo votes by users with less than x reputation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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