From da317b5a858b6c30d827230d6e0a0f426bd6959b Mon Sep 17 00:00:00 2001 From: MrWaffle Date: Wed, 22 Jan 2014 20:27:42 +0100 Subject: [PATCH] async wooo --- src/favourites.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/favourites.js b/src/favourites.js index bf0259502f..be3636ebd2 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -1,4 +1,6 @@ -var db = require('./database'), +var async = require('async'), + + db = require('./database'), posts = require('./posts'), user = require('./user'), translator = require('./../public/src/translator'); @@ -116,22 +118,18 @@ var db = require('./database'), }; Favourites.getFavouritedUidsByPids = function (pids, callback) { - //Might as well take the method above this as an example - var loaded = 0; var data = {}; - for (var i = 0, ii = pids.length; i < ii; i++) { - (function (post_id) { - db.getSetMembers('pid:' + post_id + ':users_favourited', function(err, uids) { - data[post_id] = uids; - loaded++; - if (loaded === pids.length) { - callback(data); - } - }); - }(pids[i])); + function getUids(pid, next) { + db.getSetMembers('pid:' + pid + ':users_favourited', function(err, uids) { + data[pid] = uids; + next(); + }); } - //Literally + + async.each(pids, getUids, function(err) { + callback(data); + }); }; }(exports)); \ No newline at end of file