mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
posts:votes sorted set
This commit is contained in:
@@ -248,6 +248,9 @@ var plugins = require('./plugins');
|
|||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
},
|
},
|
||||||
|
function (next) {
|
||||||
|
db.sortedSetAdd('posts:votes', postData.votes, postData.pid, next);
|
||||||
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
Posts.setPostFields(postData.pid, { upvotes: postData.upvotes, downvotes: postData.downvotes }, next);
|
Posts.setPostFields(postData.pid, { upvotes: postData.upvotes, downvotes: postData.downvotes }, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var schemaDate;
|
|||||||
var thisSchemaDate;
|
var thisSchemaDate;
|
||||||
|
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// 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) {
|
Upgrade.check = function (callback) {
|
||||||
db.get('schemaDate', function (err, value) {
|
db.get('schemaDate', function (err, value) {
|
||||||
@@ -479,6 +479,50 @@ Upgrade.upgrade = function (callback) {
|
|||||||
next();
|
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);
|
||||||
|
|
||||||
|
db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.eachSeries(cids, function (cid, next) {
|
||||||
|
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, -1, function (err, pids) {
|
||||||
|
if (err || !pids) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// Add new schema updates here
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||||
], function (err) {
|
], function (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user