Undo reputations

Technical Support
  • Hi, we had a problem that I made an issue for it.

    Can we Undo the reputations that the system has given to users?

  • Not from the UI, but you can change a users reputation in the database, the two places you need to modify are the users objects at user:<uid> the field name is reputation. And the sorted set users:reputation where you need to set the score to the new reputation. Below are the sample mongodb queries you need to run to set the users reputation to X.

    db.objects.update({_key: "user:<replace_with_uid>"}, {$set: {"reputation": X}});
    db.objects.update({_key: "users:reputation", value: "<replace_with_uid>"}, {$set: {"score": X}});
    
  • @baris Thank you sir. You have been a big help 🙏

  • @baris said in Undo reputations:

    Not from the UI, but you can change a users reputation in the database, the two places you need to modify are the users objects at user:<uid> the field name is reputation. And the sorted set users:reputation where you need to set the score to the new reputation. Below are the sample mongodb queries you need to run to set the users reputation to X.

    db.objects.update({_key: "user:<replace_with_uid>"}, {$set: {"reputation": X}});
    db.objects.update({_key: "users:reputation", value: "<replace_with_uid>"}, {$set: {"score": X}});
    

    What is reputation Algorithm?
    maybe we can recalculate it for every users. And update it.

  • Thats good idea.
    @baris Do we have a command or script to calculate the reputation of the users?
    I mean can we find the real reputation that users had earned with posts?

  • There is no reputation algorithm as far as I know. It's just a number stored in the database.

  • 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);
    	});
    });
    

Suggested Topics