From 23fb904fa6862c435ca75987d1b591ac6621e201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 25 Jun 2019 10:00:55 -0400 Subject: [PATCH] feat: removed series from upgrade script --- src/upgrades/1.12.3/user_pid_sets.js | 55 ++++++++++++---------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/upgrades/1.12.3/user_pid_sets.js b/src/upgrades/1.12.3/user_pid_sets.js index d3f5b126a5..060595db0a 100644 --- a/src/upgrades/1.12.3/user_pid_sets.js +++ b/src/upgrades/1.12.3/user_pid_sets.js @@ -14,39 +14,30 @@ module.exports = { const progress = this.progress; batch.processSortedSet('posts:pid', function (pids, next) { - async.eachSeries(pids, function (pid, _next) { - progress.incr(); - let postData; - - async.waterfall([ - function (next) { - posts.getPostFields(pid, ['uid', 'tid', 'upvotes', 'downvotes', 'timestamp'], next); - }, - function (_postData, next) { - if (!_postData.uid || !_postData.tid) { - return _next(); - } - postData = _postData; - topics.getTopicField(postData.tid, 'cid', next); - }, - function (cid, next) { - const keys = [ - 'cid:' + cid + ':uid:' + postData.uid + ':pids', - ]; - const scores = [ - postData.timestamp, - ]; - if (postData.votes > 0) { - keys.push('cid:' + cid + ':uid:' + postData.uid + ':pids:votes'); - scores.push(postData.votes); + progress.incr(pids.length); + let postData; + async.waterfall([ + function (next) { + posts.getPostsFields(pids, ['uid', 'tid', 'upvotes', 'downvotes', 'timestamp'], next); + }, + function (_postData, next) { + postData = _postData; + const tids = postData.map(p => p.tid); + topics.getTopicsFields(tids, ['cid'], next); + }, + function (topicData, next) { + const bulk = []; + postData.forEach(function (p, index) { + if (p && p.uid && p.tid) { + bulk.push(['cid:' + topicData[index].cid + ':uid:' + p.uid + ':pids', p.timestamp, p.pid]); + if (p.votes > 0) { + bulk.push(['cid:' + topicData[index].cid + ':uid:' + p.uid + ':pids:votes', p.votes, p.pid]); + } } - db.sortedSetsAdd(keys, scores, pid, next); - }, - function (next) { - db.sortedSetRemove('uid:' + postData.uid + ':posts:votes', pid, next); - }, - ], _next); - }, next); + }); + db.sortedSetAddBulk(bulk, next); + }, + ], next); }, { progress: progress, }, callback);