changed to async.eachSeries

This commit is contained in:
Baris Usakli
2013-07-19 15:26:29 -04:00
parent c1b170ec86
commit ff9990701b
3 changed files with 26 additions and 25 deletions

View File

@@ -107,28 +107,29 @@ marked.setOptions({
} }
Posts.getPostsByPids = function(pids, callback) { Posts.getPostsByPids = function(pids, callback) {
var posts = [], var posts = [];
loaded = 0;
for(var i=0, ii=pids.length; i<ii; ++i) { function iterator(pid, callback) {
(function(index, pid) { Posts.getPostData(pid, function(postData) {
Posts.getPostData(pid, function(postData) { if(postData) {
postData.relativeTime = utils.relativeTime(postData.timestamp);
if(postData) { postData.post_rep = postData.reputation;
postData.relativeTime = utils.relativeTime(postData.timestamp); postData['edited-class'] = postData.editor !== '' ? '' : 'none';
postData.post_rep = postData.reputation; postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
postData['edited-class'] = postData.editor !== '' ? '' : 'none'; postData.content = marked(postData.content || '');
postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : ''; posts.push(postData);
postData.content = marked(postData.content || ''); }
posts[index] = postData; callback(null);
} });
++loaded;
if(loaded === pids.length)
callback(posts);
});
}(i, pids[i]));
} }
async.eachSeries(pids, iterator, function(err) {
if(!err) {
callback(posts);
} else {
callback([]);
}
});
} }
Posts.getPostField = function(pid, field, callback) { Posts.getPostField = function(pid, field, callback) {

View File

@@ -267,7 +267,7 @@ marked.setOptions({
Topics.getTeasers = function(tids, callback) { Topics.getTeasers = function(tids, callback) {
var teasers = []; var teasers = [];
if (Array.isArray(tids)) { if (Array.isArray(tids)) {
async.each(tids, function(tid, next) { async.eachSeries(tids, function(tid, next) {
Topics.getTeaser(tid, function(err, teaser_info) { Topics.getTeaser(tid, function(err, teaser_info) {
if (err) teaser_info = {}; if (err) teaser_info = {};
teasers.push(teaser_info); teasers.push(teaser_info);

View File

@@ -156,7 +156,7 @@ var utils = require('./../public/src/utils.js'),
}); });
} }
async.each(uuids, iterator, function(err) { async.eachSeries(uuids, iterator, function(err) {
if(!err) { if(!err) {
callback(returnData); callback(returnData);
} else { } else {
@@ -556,7 +556,7 @@ var utils = require('./../public/src/utils.js'),
}); });
} }
async.each(uids, iterator, function(err) { async.eachSeries(uids, iterator, function(err) {
callback(returnData); callback(returnData);
}); });
} }
@@ -641,7 +641,7 @@ var utils = require('./../public/src/utils.js'),
}); });
} }
async.each(uids, iterator, function(err) { async.eachSeries(uids, iterator, function(err) {
callback(usernames); callback(usernames);
}); });
} }
@@ -660,7 +660,7 @@ var utils = require('./../public/src/utils.js'),
}); });
} }
async.each(uids, iterator, function(err) { async.eachSeries(uids, iterator, function(err) {
callback(userslugs); callback(userslugs);
}); });
} }