From fced152e4113cda91214737c2b6c98e0fd3028a8 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 13 Oct 2014 15:06:21 -0400 Subject: [PATCH] read total from global object --- src/controllers/admin.js | 13 +++++++------ src/middleware/middleware.js | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/controllers/admin.js b/src/controllers/admin.js index 8f6e898d2a..e5f0461785 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -70,16 +70,16 @@ adminController.home = function(req, res, next) { function getStats(callback) { async.parallel([ function(next) { - getStatsForSet('ip:recent', next); + getStatsForSet('ip:recent', 'uniqueIPCount', next); }, function(next) { - getStatsForSet('users:joindate', next); + getStatsForSet('users:joindate', 'userCount', next); }, function(next) { - getStatsForSet('posts:pid', next); + getStatsForSet('posts:pid', 'postCount', next); }, function(next) { - getStatsForSet('topics:tid', next); + getStatsForSet('topics:tid', 'topicCount', next); } ], function(err, results) { if (err) { @@ -94,12 +94,13 @@ function getStats(callback) { }); } -function getStatsForSet(set, callback) { +function getStatsForSet(set, field, callback) { var terms = { day: 86400000, week: 604800000, month: 2592000000 }; + var now = Date.now(); async.parallel({ day: function(next) { @@ -112,7 +113,7 @@ function getStatsForSet(set, callback) { db.sortedSetCount(set, now - terms.month, now, next); }, alltime: function(next) { - db.sortedSetCount(set, 0, now, next); + db.getObjectField('global', field, next); } }, callback); } diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 1690a29959..599689e647 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -51,7 +51,9 @@ middleware.updateLastOnlineTime = function(req, res, next) { } var today = new Date(); today.setHours(today.getHours(), 0, 0, 0); - + if (!score) { + db.incrObjectField('global', 'uniqueIPCount'); + } if (!score || score < today.getTime()) { db.sortedSetIncrBy('analytics:uniquevisitors', 1, today.getTime()); db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown');