Thought I'd refactor this for you guys

v1.18.x
MrWaffle 11 years ago
parent da317b5a85
commit 03d92eb5cd

@ -100,21 +100,18 @@ var async = require('async'),
}; };
Favourites.getFavouritesByPostIDs = function (pids, uid, callback) { Favourites.getFavouritesByPostIDs = function (pids, uid, callback) {
var loaded = 0;
var data = {}; var data = {};
for (var i = 0, ii = pids.length; i < ii; i++) { function iterator(pid, next) {
(function (post_id) { Favourites.hasFavourited(pid, uid, function (hasFavourited) {
Favourites.hasFavourited(post_id, uid, function (hasFavourited) { data[pid] = hasFavourited;
next()
data[post_id] = hasFavourited; });
loaded++;
if (loaded === pids.length) {
callback(data);
}
});
}(pids[i]));
} }
async.each(pids, iterator, function(err) {
callback(data);
});
}; };
Favourites.getFavouritedUidsByPids = function (pids, callback) { Favourites.getFavouritedUidsByPids = function (pids, callback) {

Loading…
Cancel
Save