converted pageviews tracking to sorted set, and using pre-built getStatsForSet function

thanks @barisusakli
v1.18.x
psychobunny 10 years ago
parent 80ca6bb0a2
commit 144992426d

@ -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);
});

@ -49,28 +49,12 @@ 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);
today.setDate(today.getDate());
today.setHours(today.getHours(), 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());
});
db.sortedSetIncrBy('analytics:pageviews', 1, today.getTime());
next();
};

@ -23,18 +23,6 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Pageviews</div>
<div class="panel-body">
<div class="col-xs-6 text-center">
<h3>Monthly<br /><small>{pageviews.monthly}</small></h3>
</div>
<div class="col-xs-6 text-center">
<h3>Daily<br /><small>{pageviews.daily}</small></h3>
</div>
</div>
</div>
<!-- BEGIN stats -->
<div class="panel panel-default">
<div class="panel-heading">{stats.name}</div>

Loading…
Cancel
Save