Improved simulation leaderboard performance

This commit is contained in:
Michael Schmatz 2014-04-14 11:39:30 -07:00
parent 239b130d9c
commit 6c4349df70

View file

@ -165,13 +165,11 @@ UserHandler = class UserHandler extends Handler
simulatedByQuery[if req.query.order is 1 then "$gt" else "$lte"] = req.query.scoreOffset
query.simulatedBy = simulatedByQuery
sortOrder = 1 if req.query.order is 1
aggregation = User.aggregate [
{$match: query}
{$project:{"name":1, "simulatedBy": 1, "simulatedFor":1}}
{$sort: {"simulatedBy":sortOrder}}
{$limit: limit}
]
aggregation.exec (err, otherUsers) ->
else
query.simulatedBy = {"$exists": true}
leaderboardQuery = User.find(query).select("name simulatedBy simulatedFor").sort({"simulatedBy":sortOrder}).limit(limit)
leaderboardQuery.exec (err, otherUsers) ->
otherUsers = _.reject otherUsers, _id: req.user._id if req.query.scoreOffset isnt -1
otherUsers ?= []
res.send(otherUsers)