feat: use db.sortedSetsAdd

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 68e5d7adec
commit 29a124c412

@ -179,16 +179,24 @@ module.exports = function (Topics) {
if (pin) { if (pin) {
async.parallel([ async.parallel([
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids:pinned', Date.now(), tid), async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids:pinned', Date.now(), tid),
async.apply(db.sortedSetRemove, 'cid:' + topicData.cid + ':tids', tid), async.apply(db.sortedSetsRemove, [
async.apply(db.sortedSetRemove, 'cid:' + topicData.cid + ':tids:posts', tid), 'cid:' + topicData.cid + ':tids',
async.apply(db.sortedSetRemove, 'cid:' + topicData.cid + ':tids:votes', tid), 'cid:' + topicData.cid + ':tids:posts',
'cid:' + topicData.cid + ':tids:votes',
], tid),
], next); ], next);
} else { } else {
async.parallel([ async.parallel([
async.apply(db.sortedSetRemove, 'cid:' + topicData.cid + ':tids:pinned', tid), async.apply(db.sortedSetRemove, 'cid:' + topicData.cid + ':tids:pinned', tid),
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids', topicData.lastposttime, tid), async.apply(db.sortedSetsAdd, [
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids:posts', topicData.postcount, tid), 'cid:' + topicData.cid + ':tids',
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids:votes', parseInt(topicData.votes, 10) || 0, tid), 'cid:' + topicData.cid + ':tids:posts',
'cid:' + topicData.cid + ':tids:votes',
], [
topicData.lastposttime,
topicData.postcount,
parseInt(topicData.votes, 10) || 0,
], tid),
], next); ], next);
} }
}, },
@ -208,9 +216,7 @@ module.exports = function (Topics) {
var cid; var cid;
async.waterfall([ async.waterfall([
function (next) { function (next) {
var tids = data.map(function (topic) { const tids = data.map(topic => topic && topic.tid);
return topic && topic.tid;
});
Topics.getTopicsFields(tids, ['cid'], next); Topics.getTopicsFields(tids, ['cid'], next);
}, },
function (topicData, next) { function (topicData, next) {
@ -272,32 +278,18 @@ module.exports = function (Topics) {
'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids', 'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids',
], tid, next); ], tid, next);
}, },
function (next) {
db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', topic.lastposttime, tid, next);
},
function (next) {
db.sortedSetAdd('cid:' + cid + ':uid:' + topic.uid + ':tids', topic.timestamp, tid, next);
},
function (next) {
if (topic.pinned) {
db.sortedSetAdd('cid:' + cid + ':tids:pinned', Date.now(), tid, next);
} else {
async.parallel([
function (next) {
db.sortedSetAdd('cid:' + cid + ':tids', topic.lastposttime, tid, next);
},
function (next) { function (next) {
topic.postcount = topic.postcount || 0; topic.postcount = topic.postcount || 0;
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next); const votes = topic.upvotes - topic.downvotes;
}, db.sortedSetsAdd([
function (next) { 'cid:' + cid + ':tids:lastposttime',
var votes = topic.upvotes - topic.downvotes; 'cid:' + cid + ':uid:' + topic.uid + ':tids',
db.sortedSetAdd('cid:' + cid + ':tids:votes', votes, tid, next); ...(topic.pinned ? ['cid:' + cid + ':tids:pinned'] : ['cid:' + cid + ':tids', 'cid:' + cid + ':tids:posts', 'cid:' + cid + ':tids:votes']),
}, ], [
], function (err) { topic.lastposttime,
next(err); topic.timestamp,
}); ...(topic.pinned ? [Date.now()] : [topic.lastposttime, topic.postcount, votes]),
} ], tid, next);
}, },
function (next) { function (next) {
oldCid = topic.cid; oldCid = topic.cid;

Loading…
Cancel
Save