mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-13 21:44:40 -04:00
Do user level sessions sort post-fetch\n\nOtherwise it would blow Mongo's sort memory limits if done during the query on large sessions fetches like on my user page, and we don't need to sort then anyway 'cause we're grabbing all the sessions.
This commit is contained in:
parent
7b54a04d33
commit
6f3bd848a9
1 changed files with 5 additions and 3 deletions
|
@ -517,11 +517,13 @@ UserHandler = class UserHandler extends Handler
|
|||
projection[field] = 1 for field in req.query.project.split(',') when isAuthorized or not (field in LevelSessionHandler.privateProperties)
|
||||
else unless isAuthorized
|
||||
projection[field] = 0 for field in LevelSessionHandler.privateProperties
|
||||
sort = {}
|
||||
sort.changed = req.query.order if req.query.order
|
||||
|
||||
LevelSession.find(query).select(projection).sort(sort).exec (err, documents) =>
|
||||
LevelSession.find(query).select(projection).exec (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
if req.query.order
|
||||
documents = _.sortBy documents, 'changed'
|
||||
if req.query.order + '' is '-1'
|
||||
documents.reverse()
|
||||
documents = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, documents)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue