shorter getTeasers

This commit is contained in:
barisusakli
2014-11-18 22:19:17 -05:00
parent 5292a47a96
commit 871cf8a3b7
2 changed files with 8 additions and 13 deletions

View File

@@ -18,17 +18,8 @@ module.exports = function(Topics) {
}
async.parallel({
counts: function(next) {
Topics.getTopicsFields(tids, ['postcount'], function(err, topics) {
if (err) {
return next(err);
}
topics = topics.map(function(topic) {
return topic && (parseInt(topic.postcount, 10) || 0);
});
next(null, topics);
});
topics: function(next) {
Topics.getTopicsFields(tids, ['postcount'], next);
},
pids: function(next) {
async.map(tids, function(tid, next) {
@@ -42,6 +33,10 @@ module.exports = function(Topics) {
return callback(err);
}
var counts = results.topics.map(function(topic) {
return topic && (parseInt(topic.postcount, 10) || 0);
});
results.pids = results.pids.filter(Boolean);
posts.getPostsFields(results.pids, ['pid', 'uid', 'timestamp', 'tid'], function(err, postData) {
@@ -74,7 +69,7 @@ module.exports = function(Topics) {
var teasers = tids.map(function(tid, index) {
if (tidToPost[tid]) {
tidToPost[tid].index = results.counts[index];
tidToPost[tid].index = counts[index];
}
return tidToPost[tid];
});