From 6c4349df70dbf829d315afb6f0f995c99fd7894b Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Mon, 14 Apr 2014 11:39:30 -0700 Subject: [PATCH] Improved simulation leaderboard performance --- server/users/user_handler.coffee | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index 7ed012d52..0c128e31a 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -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)