feat: use db.sortedSetsAdd

v1.18.x
Barış Soner Uşaklı
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) {
@ -273,31 +279,17 @@ module.exports = function (Topics) {
], tid, next); ], tid, next);
}, },
function (next) { function (next) {
db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', topic.lastposttime, tid, next); topic.postcount = topic.postcount || 0;
}, const votes = topic.upvotes - topic.downvotes;
function (next) { db.sortedSetsAdd([
db.sortedSetAdd('cid:' + cid + ':uid:' + topic.uid + ':tids', topic.timestamp, tid, next); 'cid:' + cid + ':tids:lastposttime',
}, 'cid:' + cid + ':uid:' + topic.uid + ':tids',
function (next) { ...(topic.pinned ? ['cid:' + cid + ':tids:pinned'] : ['cid:' + cid + ':tids', 'cid:' + cid + ':tids:posts', 'cid:' + cid + ':tids:votes']),
if (topic.pinned) { ], [
db.sortedSetAdd('cid:' + cid + ':tids:pinned', Date.now(), tid, next); topic.lastposttime,
} else { topic.timestamp,
async.parallel([ ...(topic.pinned ? [Date.now()] : [topic.lastposttime, topic.postcount, votes]),
function (next) { ], tid, next);
db.sortedSetAdd('cid:' + cid + ':tids', topic.lastposttime, tid, next);
},
function (next) {
topic.postcount = topic.postcount || 0;
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next);
},
function (next) {
var votes = topic.upvotes - topic.downvotes;
db.sortedSetAdd('cid:' + cid + ':tids:votes', votes, tid, next);
},
], function (err) {
next(err);
});
}
}, },
function (next) { function (next) {
oldCid = topic.cid; oldCid = topic.cid;

Loading…
Cancel
Save