shorter getTeasers

v1.18.x
barisusakli 10 years ago
parent 5292a47a96
commit 871cf8a3b7

@ -16,7 +16,7 @@ var async = require('async'),
module.exports = function(Posts) {
Posts.getPostSummaryByPids = function(pids, uid, options, callback) {
if (!pids || !Array.isArray(pids) || !pids.length) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}

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

Loading…
Cancel
Save