mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 23:30:36 +01:00
closes #6214
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
53
src/upgrades/1.8.0/fix_moved_topics_byvotes.js
Normal file
53
src/upgrades/1.8.0/fix_moved_topics_byvotes.js
Normal file
@@ -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);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user