mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Fix sorting crashing bug
This commit is contained in:
parent
95f76ae9d8
commit
3d1ee9767f
1 changed files with 5 additions and 2 deletions
|
@ -126,6 +126,7 @@ module.exports.getTwoGames = (req, res) ->
|
|||
ogresGameID = req.body.ogresGameID
|
||||
ladderGameIDs = ['greed', 'criss-cross', 'brawlwood', 'dungeon-arena', 'gold-rush', 'sky-span', 'dueling-grounds', 'cavern-survival', 'multiplayer-treasure-grove']
|
||||
levelID = _.sample ladderGameIDs
|
||||
sortLimit = 5000
|
||||
unless ogresGameID and humansGameID
|
||||
#fetch random games here
|
||||
queryParams =
|
||||
|
@ -138,6 +139,7 @@ module.exports.getTwoGames = (req, res) ->
|
|||
unless numberOfHumans
|
||||
res.send(204, 'No games to score.')
|
||||
return res.end()
|
||||
numberOfHumans = Math.min numberOfHumans, sortLimit
|
||||
humanSkipCount = Math.floor(Math.random() * numberOfHumans)
|
||||
ogreCountParams =
|
||||
'levelID': levelID
|
||||
|
@ -148,14 +150,15 @@ module.exports.getTwoGames = (req, res) ->
|
|||
unless numberOfOgres
|
||||
res.send(204, 'No games to score.')
|
||||
return res.end()
|
||||
numberOfOgres = Math.min numberOfOgres, sortLimit
|
||||
ogresSkipCount = Math.floor(Math.random() * numberOfOgres)
|
||||
|
||||
query = LevelSession
|
||||
.aggregate()
|
||||
.match(queryParams)
|
||||
.project(selection)
|
||||
.limit(5000)
|
||||
.sort({'submitDate': -1})
|
||||
.limit(sortLimit)
|
||||
.skip(humanSkipCount)
|
||||
.limit(1)
|
||||
query.exec (err, randomSession) =>
|
||||
|
@ -169,8 +172,8 @@ module.exports.getTwoGames = (req, res) ->
|
|||
.aggregate()
|
||||
.match(queryParams)
|
||||
.project(selection)
|
||||
.limit(5000)
|
||||
.sort({'submitDate': -1})
|
||||
.limit(sortLimit)
|
||||
.skip(ogresSkipCount)
|
||||
.limit(1)
|
||||
query.exec (err, otherSession) =>
|
||||
|
|
Loading…
Reference in a new issue