You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/upgrades/1.5.0/post_votes_zset.js

32 lines
787 B
JavaScript

/* jslint node: true */
'use strict';
var db = require('../../database');
var async = require('async');
module.exports = {
name: 'New sorted set posts:votes',
timestamp: Date.UTC(2017, 1, 27),
method: function (callback) {
var progress = this.progress;
require('../../batch').processSortedSet('posts:pid', function (pids, next) {
async.each(pids, function (pid, next) {
db.getObjectFields('post:' + pid, ['upvotes', 'downvotes'], function (err, postData) {
if (err || !postData) {
return next(err);
}
progress.incr();
var votes = parseInt(postData.upvotes || 0, 10) - parseInt(postData.downvotes || 0, 10);
db.sortedSetAdd('posts:votes', votes, pid, next);
});
}, next);
}, {
progress: this.progress,
}, callback);
},
};