another waterfall

v1.18.x
barisusakli 10 years ago
parent 8f98d03239
commit 3c63336063

@ -22,39 +22,36 @@ module.exports = function(Topics) {
var counts = []; var counts = [];
var teaserPids = []; var teaserPids = [];
var postData;
var tidToPost = {};
topics.forEach(function(topic) { topics.forEach(function(topic) {
counts.push(topic && (parseInt(topic.postcount, 10) || 0)); counts.push(topic && (parseInt(topic.postcount, 10) || 0));
if (topic) { if (topic) {
if (meta.config.teaserPost === 'first') { teaserPids.push(meta.config.teaserPost === 'first' ? topic.mainPid : topic.teaserPid);
teaserPids.push(topic.mainPid);
} else {
teaserPids.push(topic.teaserPid);
}
} }
}); });
posts.getPostsFields(teaserPids, ['pid', 'uid', 'timestamp', 'tid', 'content'], function(err, postData) { async.waterfall([
if (err) { function(next) {
return callback(err); posts.getPostsFields(teaserPids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
} },
function(_postData, next) {
postData = _postData;
var uids = postData.map(function(post) { var uids = postData.map(function(post) {
return post.uid; return post.uid;
}).filter(function(uid, index, array) { }).filter(function(uid, index, array) {
return array.indexOf(uid) === index; return array.indexOf(uid) === index;
}); });
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], function(err, usersData) { user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
if (err) { },
return callback(err); function(usersData, next) {
}
var users = {}; var users = {};
usersData.forEach(function(user) { usersData.forEach(function(user) {
users[user.uid] = user; users[user.uid] = user;
}); });
var tidToPost = {};
async.each(postData, function(post, next) { async.each(postData, function(post, next) {
// If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest. // If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.
@ -66,10 +63,9 @@ module.exports = function(Topics) {
post.timestamp = utils.toISOString(post.timestamp); post.timestamp = utils.toISOString(post.timestamp);
tidToPost[post.tid] = post; tidToPost[post.tid] = post;
posts.parsePost(post, next); posts.parsePost(post, next);
}, function(err) { }, next);
if (err) { },
return callback(err); function(next) {
}
var teasers = topics.map(function(topic, index) { var teasers = topics.map(function(topic, index) {
if (!topic) { if (!topic) {
return null; return null;
@ -84,12 +80,12 @@ module.exports = function(Topics) {
return tidToPost[topic.tid]; return tidToPost[topic.tid];
}); });
plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) { plugins.fireHook('filter:teasers.get', {teasers: teasers}, next);
callback(err, data ? data.teasers : null); },
}); function(data, next) {
}); next(null, data.teasers);
}); }
}); ], callback);
}; };
Topics.getTeasersByTids = function(tids, callback) { Topics.getTeasersByTids = function(tids, callback) {

Loading…
Cancel
Save