From 128ef884bf9a3aca85e42649aff1293dc2b0ee6a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 3 Oct 2016 18:56:39 +0300 Subject: [PATCH] #5077 --- src/topics.js | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/src/topics.js b/src/topics.js index 3248d8f567..9fb8f827a8 100644 --- a/src/topics.js +++ b/src/topics.js @@ -345,7 +345,7 @@ var social = require('./social'); } }; - Topics.getTopicBookmarks = function( tid, callback ){ + Topics.getTopicBookmarks = function(tid, callback) { db.getSortedSetRangeWithScores(['tid:' + tid + ':bookmarks'], 0, -1, callback); }; @@ -372,49 +372,26 @@ var social = require('./social'); }; }); - async.map(uidData, function(data, mapCallback) { - posts.getPostIndices(forkedPosts, data.uid, function(err, indices) { + async.eachLimit(uidData, 50, function(data, next) { + posts.getPostIndices(forkedPosts, data.uid, function(err, postIndices) { if (err) { - return callback(err); + return next(err); } - data.postIndices = indices; - mapCallback(null, data); - }); - }, function(err, results) { - if (err) { - return callback(err); - } - async.map(results, function(data, mapCallback) { - var uid = data.uid; + var bookmark = data.bookmark; bookmark = bookmark < maxIndex ? bookmark : maxIndex; - var postIndices = data.postIndices; - for (var i = 0; i < postIndices.length && postIndices[i] < data.bookmark; ++i ){ + for (var i = 0; i < postIndices.length && postIndices[i] < data.bookmark; ++i) { --bookmark; } if (parseInt(bookmark, 10) !== parseInt(data.bookmark, 10)) { - mapCallback( null, { uid: uid, bookmark: bookmark } ); + Topics.setUserBookmark(tid, data.uid, bookmark, next); } else { - mapCallback( null, null ); - } - }, function(err, results) { - if (err) { - return callback(err); + next(); } - - async.map(results, function(ui, cb) { - if( ui && ui.bookmark) { - Topics.setUserBookmark(tid, ui.uid, ui.bookmark, cb); - } else { - return cb(null, null); - } - }, function(err) { - next(err); - }); }); - }); + }, next); } ], function(err){ callback(err);