parent
762dac6a4a
commit
5c7dd54815
@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var db = require('../../database');
|
||||
|
||||
var async = require('async');
|
||||
var batch = require('../../batch');
|
||||
|
||||
module.exports = {
|
||||
name: 'Fix category post zsets',
|
||||
timestamp: Date.UTC(2018, 9, 10),
|
||||
method: function (callback) {
|
||||
const progress = this.progress;
|
||||
|
||||
db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var keys = cids.map(function (cid) {
|
||||
return 'cid:' + cid + ':pids';
|
||||
});
|
||||
var posts = require('../../posts');
|
||||
batch.processSortedSet('posts:pid', function (postData, next) {
|
||||
async.eachSeries(postData, function (postData, next) {
|
||||
progress.incr();
|
||||
var pid = postData.value;
|
||||
var timestamp = postData.score;
|
||||
var cid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
posts.getCidByPid(pid, next);
|
||||
},
|
||||
function (_cid, next) {
|
||||
cid = _cid;
|
||||
db.isMemberOfSortedSets(keys, pid, next);
|
||||
},
|
||||
function (isMembers, next) {
|
||||
var memberCids = [];
|
||||
isMembers.forEach(function (isMember, index) {
|
||||
if (isMember) {
|
||||
memberCids.push(cids[index]);
|
||||
}
|
||||
});
|
||||
if (memberCids.length > 1) {
|
||||
async.waterfall([
|
||||
async.apply(db.sortedSetRemove, memberCids.map(cid => 'cid:' + cid + ':pids'), pid),
|
||||
async.apply(db.sortedSetAdd, 'cid:' + cid + ':pids', timestamp, pid),
|
||||
], next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}, next);
|
||||
}, {
|
||||
progress: progress,
|
||||
withScores: true,
|
||||
}, callback);
|
||||
});
|
||||
},
|
||||
};
|
@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var db = require('../../database');
|
||||
|
||||
var async = require('async');
|
||||
var batch = require('../../batch');
|
||||
|
||||
module.exports = {
|
||||
name: 'Fix category topic zsets',
|
||||
timestamp: Date.UTC(2018, 9, 11),
|
||||
method: function (callback) {
|
||||
const progress = this.progress;
|
||||
|
||||
var topics = require('../../topics');
|
||||
batch.processSortedSet('topics:tid', function (tids, next) {
|
||||
async.eachSeries(tids, function (tid, next) {
|
||||
progress.incr();
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getObjectFields('topic:' + tid, ['cid', 'pinned', 'postcount'], next);
|
||||
},
|
||||
function (topicData, next) {
|
||||
if (parseInt(topicData.pinned, 10) === 1) {
|
||||
return setImmediate(next);
|
||||
}
|
||||
|
||||
db.sortedSetAdd('cid:' + topicData.cid + ':tids:posts', topicData.postcount, tid, next);
|
||||
},
|
||||
function (next) {
|
||||
topics.updateLastPostTimeFromLastPid(tid, next);
|
||||
},
|
||||
], next);
|
||||
}, next);
|
||||
}, {
|
||||
progress: progress,
|
||||
}, callback);
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue