Merge pull request #5487 from NodeBB/posts-votes-sorted-set

posts:votes sorted set
v1.18.x
psychobunny 8 years ago committed by GitHub
commit 43bf422cba

@ -248,6 +248,9 @@ var plugins = require('./plugins');
},
], next);
},
function (next) {
db.sortedSetAdd('posts:votes', postData.votes, postData.pid, next);
},
function (next) {
Posts.setPostFields(postData.pid, { upvotes: postData.upvotes, downvotes: postData.downvotes }, next);
},

@ -12,7 +12,7 @@ var schemaDate;
var thisSchemaDate;
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
var latestSchema = Date.UTC(2017, 1, 25);
var latestSchema = Date.UTC(2017, 1, 27);
Upgrade.check = function (callback) {
db.get('schemaDate', function (err, value) {
@ -479,6 +479,38 @@ Upgrade.upgrade = function (callback) {
next();
}
},
function (next) {
thisSchemaDate = Date.UTC(2017, 1, 27);
var schemaName = '[2017/2/27] New sorted set posts:votes';
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.verbose(schemaName);
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);
}
var votes = parseInt(postData.upvotes || 0, 10) - parseInt(postData.downvotes || 0, 10);
db.sortedSetAdd('posts:votes', votes, pid, next);
});
}, next);
}, {}, function (err) {
if (err) {
return next(err);
}
winston.info(schemaName + ' - done');
Upgrade.update(thisSchemaDate, next);
});
} else {
winston.info(schemaName + ' - skipped!');
next();
}
},
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
], function (err) {

Loading…
Cancel
Save