From 633980ce4bdac3d58fd0e276147eb6248f9bd260 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 13 Jul 2014 14:57:55 -0400 Subject: [PATCH] active users cleanup --- src/categories/activeusers.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/categories/activeusers.js b/src/categories/activeusers.js index 57873944b8..56a7832236 100644 --- a/src/categories/activeusers.js +++ b/src/categories/activeusers.js @@ -1,23 +1,23 @@ 'use strict'; var async = require('async'), - db = require('./../database'), - posts = require('./../posts'), - topics = require('./../topics'); + db = require('../database'); module.exports = function(Categories) { Categories.getActiveUsers = function(cid, callback) { - db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 99, function(err, pids) { - var keys = pids.map(function(pid) { - return 'post:' + pid; - }); - - db.getObjectsFields(keys, ['uid'], function(err, users) { - if (err) { - return callback(err); - } + async.waterfall([ + function(next) { + db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 99, next); + }, + function(pids, next) { + var keys = pids.map(function(pid) { + return 'post:' + pid; + }); + db.getObjectsFields(keys, ['uid'], next); + }, + function(users, next) { var uids = users.map(function(user) { return user.uid; }).filter(function(value, index, array) { @@ -25,7 +25,7 @@ module.exports = function(Categories) { }).slice(0, 24); callback(null, uids); - }); - }); + } + ], callback); }; };