read total from global object

v1.18.x
barisusakli 10 years ago
parent be0d043b2b
commit fced152e41

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

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

Loading…
Cancel
Save