Skip to content

Node.js based forum software built for the modern web

filter before getting topics

barisusaklicf5ac4fb7451
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);
+ });
});
}
};