v1.18.x
Barış Soner Uşaklı 7 years ago
parent b58387c822
commit 9d7e0775aa

@ -274,10 +274,6 @@ module.exports = function (Topics) {
function (next) {
db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', topic.lastposttime, tid, next);
},
function (next) {
var votes = (parseInt(topic.upvotes, 10) || 0) - (parseInt(topic.downvotes, 10) || 0);
db.sortedSetAdd('cid:' + cid + ':tids:votes', votes, tid, next);
},
function (next) {
if (parseInt(topic.pinned, 10)) {
db.sortedSetAdd('cid:' + cid + ':tids:pinned', Date.now(), tid, next);
@ -290,6 +286,10 @@ module.exports = function (Topics) {
topic.postcount = topic.postcount || 0;
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next);
},
function (next) {
var votes = (parseInt(topic.upvotes, 10) || 0) - (parseInt(topic.downvotes, 10) || 0);
db.sortedSetAdd('cid:' + cid + ':tids:votes', votes, tid, next);
},
], function (err) {
next(err);
});

@ -0,0 +1,53 @@
'use strict';
var async = require('async');
var batch = require('../../batch');
var db = require('../../database');
module.exports = {
name: 'Fix sort by votes for moved topics',
timestamp: Date.UTC(2018, 0, 8),
method: function (callback) {
var progress = this.progress;
batch.processSortedSet('topics:tid', function (tids, next) {
async.eachLimit(tids, 500, function (tid, _next) {
progress.incr();
var topicData;
async.waterfall([
function (next) {
db.getObjectFields('topic:' + tid, ['cid', 'oldCid', 'upvotes', 'downvotes', 'pinned'], next);
},
function (_topicData, next) {
topicData = _topicData;
if (!topicData.cid || !topicData.oldCid) {
return _next();
}
var upvotes = parseInt(topicData.upvotes, 10) || 0;
var downvotes = parseInt(topicData.downvotes, 10) || 0;
var votes = upvotes - downvotes;
async.parallel([
function (next) {
db.sortedSetRemove('cid:' + topicData.oldCid + ':tids:votes', tid, next);
},
function (next) {
if (!parseInt(topicData.pinned, 10)) {
db.sortedSetAdd('cid:' + topicData.cid + ':tids:votes', votes, tid, next);
} else {
next();
}
},
], function (err) {
next(err);
});
},
], _next);
}, next);
}, {
progress: progress,
batch: 500,
}, callback);
},
};
Loading…
Cancel
Save