You can recalculate the reputations by using this user script. We do not guarantee the effectiveness of our scripts, and you run them at your own risk. Always back up your database before running them.
Place this in a new file in your NodeBB's root directory, and then run it with node executable:
'use strict';
/* globals require, console, process */
var nconf = require('nconf');
var async = require('async');
nconf.file({
file: 'config.json',
});
var db = require('./src/database');
db.init((err) => {
if (err) {
console.log('Error:', err.message);
process.exit(1);
}
var batch = require('./src/batch');
var posts = require('./src/posts');
var user = require('./src/user');
batch.processSortedSet('users:joindate', (uids, next) => {
async.each(uids, (uid, next) => {
// Find all posts by this uid and tally up their reputation
async.waterfall([
async.apply(db.getSortedSetRange, 'uid:' + uid + ':posts', 0, -1),
(pids, next) => {
async.map(pids, (pid, next) => {
posts.getPostFields(pid, ['upvotes', 'downvotes'], next);
}, next);
},
(data, next) => {
// Collate result set
let reputation = 0;
if (data.length) {
data.forEach((set) => {
reputation += parseInt(set.upvotes, 10) || 0;
reputation -= parseInt(set.downvotes, 10) || 0;
});
}
process.nextTick(next, null, {
uid: uid,
rep: reputation,
});
},
(data, next) => {
console.log('Resetting reputation for uid', data.uid, 'to', data.rep);
user.setUserField('user:' + data.uid, 'reputation', parseInt(data.rep, 10) || 0, next);
},
], next);
}, next);
}, {}, function (err) {
if (err) {
console.log('Error:', err.message);
}
process.exit(0);
});
});