Merge branch 'master' into production

This commit is contained in:
Nick Winter 2015-02-26 18:35:00 -08:00
commit e56569e5b5
2 changed files with 10 additions and 6 deletions

View file

@ -14,7 +14,11 @@ module.exports.connect = () ->
mongoose.connect address
mongoose.connection.once 'open', -> Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo)
mongooseCache.install(mongoose, {max: 200, maxAge: 1 * 60 * 1000, debug: false})
# Hack around Mongoose not exporting Aggregate so that we can patch its exec, too
# https://github.com/LearnBoost/mongoose/issues/1910
Level = require '../levels/Level'
Aggregate = Level.aggregate().constructor
mongooseCache.install(mongoose, {max: 200, maxAge: 1 * 60 * 1000, debug: false}, Aggregate)
module.exports.generateMongoConnectionString = ->
if not testing and config.mongo.mongoose_replica_string

View file

@ -160,13 +160,13 @@ LevelHandler = class LevelHandler extends Handler
if err then @sendDatabaseError(res, err) else @sendSuccess res, results
getHistogramData: (req, res, slug) ->
query = Session.aggregate [
aggregate = Session.aggregate [
{$match: {'levelID': slug, 'submitted': true, 'team': req.query.team}}
{$project: {totalScore: 1, _id: 0}}
]
#query.cache() # TODO: implement caching for aggregates
aggregate.cache()
query.exec (err, data) =>
aggregate.exec (err, data) =>
if err? then return @sendDatabaseError res, err
valueArray = _.pluck data, 'totalScore'
@sendSuccess res, valueArray
@ -290,11 +290,11 @@ LevelHandler = class LevelHandler extends Handler
sessionQueryParams['team'] = team
aggregate = Session.aggregate [
{$match: sessionQueryParams}
{$project: {'totalScore': 1}}
{$sort: {'totalScore': -1}}
{$limit: 20}
{$project: {'totalScore': 1}}
]
#aggregate.cache() # TODO: implement caching for aggregates
aggregate.cache()
aggregate.exec cb
async.map teams, findTop20Players.bind(@, sessionsQueryParameters), (err, map) =>