feat: cleanup, use bulk

This commit is contained in:
Barış Soner Uşaklı
2019-06-24 21:36:20 -04:00
parent 3ecd703ea3
commit 198d05875f
12 changed files with 63 additions and 129 deletions

View File

@@ -209,10 +209,14 @@ module.exports = function (Categories) {
async.parallel([
function (next) {
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);
},
function (next) {
db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', postData.timestamp, postData.tid, next);
const bulk = [
['cid:' + cid + ':pids', postData.timestamp, postData.pid],
['cid:' + cid + ':tids:lastposttime', postData.timestamp, postData.tid],
];
if (!pinned) {
bulk.push(['cid:' + cid + ':tids', postData.timestamp, postData.tid]);
}
db.sortedSetAddBulk(bulk, next);
},
function (next) {
db.incrObjectField('category:' + cid, 'post_count', next);
@@ -221,17 +225,7 @@ module.exports = function (Categories) {
if (pinned) {
return setImmediate(next);
}
async.parallel([
function (next) {
db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next);
},
function (next) {
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, next);
},
], function (err) {
next(err);
});
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, err => next(err));
},
function (next) {
Categories.updateRecentTid(cid, postData.tid, next);