simplify stats page to reduce queries

pull/9/head^2
Michael Q Larson 2015-01-07 10:50:48 -08:00
parent 406ebf58c2
commit 3f83f56acc
3 changed files with 31 additions and 79 deletions

View File

@ -32,25 +32,17 @@ module.exports = {
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, response) {
var nonprofitProjects = (trello && trello.length) || 15;
User.count({}, function(err, users) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 2}}, function(err, c2) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 4}}, function(err, c4) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 9}}, function(err, c9) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 19}}, function(err, c19) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 29}}, function(err, c29) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 39}}, function(err, c39) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 2}}, function(err, c3) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 9}}, function(err, c10) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 29}}, function(err, c30) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 53}}, function(err, all) { if (err) { debug('User err: ', err); next(err); }
res.render('resources/stats', {
title: 'Free Code Camp Stats:',
daysRunning: daysRunning,
users: users,
nonprofitProjects: nonprofitProjects,
c2: c2,
c4: c4,
c9: c9,
c19: c19,
c29: c29,
c39: c39,
c3: c3,
c10: c10,
c30: c30,
all: all
});
});
@ -58,10 +50,6 @@ module.exports = {
});
});
});
});
});
});
});
},
deployAWebsite: function deployAWebsite(req, res) {
@ -138,25 +126,17 @@ module.exports = {
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
client.get('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(trello, response) {
var nonprofitProjects = trello.length || 15;
User.count({}, function(err, users) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 2}}, function(err, c2) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 4}}, function(err, c4) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 9}}, function(err, c9) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 19}}, function(err, c19) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 29}}, function(err, c29) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 39}}, function(err, c39) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 2}}, function(err, c3) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 9}}, function(err, c10) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 29}}, function(err, c30) { if (err) { debug('User err: ', err); next(err); }
User.count({'points': {'$gt': 53}}, function(err, all) { if (err) { debug('User err: ', err); next(err); }
res.render('resources/about', {
title: 'About Free Code Camp and Our Team of Volunteers',
daysRunning: daysRunning,
users: users,
nonprofitProjects: nonprofitProjects,
c2: c2,
c4: c4,
c9: c9,
c19: c19,
c29: c29,
c39: c39,
c3: c3,
c10: c10,
c30: c30,
all: all
});
});
@ -164,10 +144,6 @@ module.exports = {
});
});
});
});
});
});
});
},
doneWithFirst100Hours: function(req, res) {

View File

@ -202,7 +202,7 @@
script(async='', src='//platform.twitter.com/widgets.js', charset='utf-8')
.panel.panel-primary
.panel-heading.landing-panel-heading.text-center Our Team of Volunteers
.panel-heading.landing-panel-heading.text-center Our Team of Volunteer Camp Counselors
.panel-body
.landing-panel-body.text-center
.col-xs-12

View File

@ -14,52 +14,28 @@
.col-xs-6.text-left
h2
a(href="https://trello.com/b/BA3xVpz9/nonprofit-projects")=nonprofitProjects
.row
.col-xs-6.text-right
h2 Total Code Campers:
.col-xs-6.text-left
h2
= users
.row
.col-xs-6.text-right
h2 Code Campers with at least...
.col-xs-6
.row
.col-xs-6.text-right
h2 2 Points:
h2 3 Points:
.col-xs-6.text-left
h2
= c2
= c3
.row
.col-xs-6.text-right
h2 4 Points:
h2 10 Points:
.col-xs-6.text-left
h2
= c4
= c10
.row
.col-xs-6.text-right
h2 9 Points:
h2 30 Points:
.col-xs-6.text-left
h2
= c9
.row
.col-xs-6.text-right
h2 19 Points:
.col-xs-6.text-left
h2
= c19
.row
.col-xs-6.text-right
h2 29 Points:
.col-xs-6.text-left
h2
= c29
.row
.col-xs-6.text-right
h2 39 Points:
.col-xs-6.text-left
h2
= c39
= c30
.row
.col-xs-6.text-right
h2 All 54 Points: