diff --git a/src/controllers/admin.js b/src/controllers/admin.js index 26830961a1..f0c80fb484 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -38,9 +38,6 @@ adminController.home = function(req, res, next) { stats: function(next) { getStats(next); }, - pageviews: function(next) { - getPageviews(next); - }, notices: function(next) { var notices = [ {done: !meta.restartRequired, doneText: 'Restart not required', notDoneText:'Restart required'}, @@ -56,24 +53,11 @@ adminController.home = function(req, res, next) { res.render('admin/index', { version: pkg.version, notices: results.notices, - stats: results.stats, - pageviews: results.pageviews + stats: results.stats }); }); }; -function getPageviews(callback) { - async.parallel({ - monthly: function(next) { - db.get('pageviews:monthly', next); - }, - daily: function(next) { - db.get('pageviews:daily', next); - } - }, function(err, results) { - callback(null, results); - }); -} function getStats(callback) { async.parallel([ function(next) { @@ -87,6 +71,9 @@ function getStats(callback) { }, function(next) { getStatsForSet('topics:tid', next); + }, + function(next) { + getStatsForSet('analytics:pageviews', next); } ], function(err, results) { if (err) { @@ -96,6 +83,7 @@ function getStats(callback) { results[1].name = 'Users'; results[2].name = 'Posts'; results[3].name = 'Topics'; + results[4].name = 'Page Views'; callback(null, results); }); diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 3b4eac0e1f..a0e688aff5 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -49,29 +49,13 @@ middleware.updateLastOnlineTime = function(req, res, next) { }; middleware.incrementPageViews = function(req, res, next) { - var nextMonth = new Date(), - nextDay = new Date(); + var today = new Date(); - nextMonth.setMonth(nextMonth.getMonth() + 1, 1); - nextMonth.setHours(0, 0, 0, 0); - - nextDay.setDate(nextDay.getDate() + 1); - nextDay.setHours(0, 0, 0, 0); - - db.increment('pageviews:monthly', function(err) { - if (err) { - return; - } - db.pexpireAt('pageviews:monthly', nextMonth.getTime()); - }); - - db.increment('pageviews:daily', function(err) { - if (err) { - return; - } - db.pexpireAt('pageviews:daily', nextDay.getTime()); - }); + today.setDate(today.getDate()); + today.setHours(today.getHours(), 0, 0, 0); + db.sortedSetIncrBy('analytics:pageviews', 1, today.getTime()); + next(); }; diff --git a/src/views/admin/index.tpl b/src/views/admin/index.tpl index 45ab4b728b..ce4249d34c 100644 --- a/src/views/admin/index.tpl +++ b/src/views/admin/index.tpl @@ -23,18 +23,6 @@ -