filter before getting topics

v1.18.x
barisusakli 10 years ago
parent 31a1f85a7e
commit cf5ac4fb74

@ -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);
});
});
}
};

Loading…
Cancel
Save