changed to async.eachSeries

v1.18.x
Baris Usakli 12 years ago
parent c1b170ec86
commit ff9990701b

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

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

@ -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) {
callback(returnData);
} 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);
});
}
@ -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);
});
}
@ -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);
});
}

Loading…
Cancel
Save