From cf5ac4fb74518462057646e1cc99ca98fe4ccdec Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 3 Oct 2014 21:37:43 -0400 Subject: [PATCH] filter before getting topics --- src/topics/popular.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/topics/popular.js b/src/topics/popular.js index c21146c8c7..b6dba43017 100644 --- a/src/topics/popular.js +++ b/src/topics/popular.js @@ -28,23 +28,6 @@ module.exports = function(Topics) { }, function(tids, next) { getTopics(tids, uid, count, next); - }, - function(topics, next) { - var tids = topics.map(function(topic) { - return topic.tid; - }); - - privileges.topics.filter('read', tids, uid, function(err, tids) { - if (err) { - return next(err); - } - - topics = topics.filter(function(topic) { - return tids.indexOf(topic.tid) !== -1; - }); - - next(null, topics); - }); } ], callback); }; @@ -65,13 +48,19 @@ module.exports = function(Topics) { return callback(err); } - topics = topics.sort(function(a, b) { + tids = topics.sort(function(a, b) { return b.postcount - a.postcount; }).slice(0, count).map(function(topic) { return topic.tid; }); - Topics.getTopicsByTids(topics, uid, callback); + privileges.topics.filter('read', tids, uid, function(err, tids) { + if (err) { + return callback(err); + } + + Topics.getTopicsByTids(tids, uid, callback); + }); }); } };