mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Making simulator stuff more efficient by using less bandwidth.
This commit is contained in:
parent
b500e5334a
commit
98b749eb1b
6 changed files with 23 additions and 14 deletions
|
@ -72,10 +72,12 @@ module.exports = class LevelLoader extends CocoClass
|
|||
url += "?team=#{@team}" if @team
|
||||
|
||||
session = new LevelSession().setURL url
|
||||
session.project = ['creator', 'team', 'heroConfig', 'codeLanguage', 'submittedCodeLanguage', 'state'] if @headless
|
||||
@sessionResource = @supermodel.loadModel(session, 'level_session', {cache: false})
|
||||
@session = @sessionResource.model
|
||||
if @opponentSessionID
|
||||
opponentSession = new LevelSession().setURL "/db/level.session/#{@opponentSessionID}"
|
||||
opponentSession.project = session.project if @headless
|
||||
@opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session', {cache: false})
|
||||
@opponentSession = @opponentSessionResource.model
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class CocoModel extends Backbone.Model
|
|||
# if fixed, RevertModal will also need the fix
|
||||
|
||||
setProjection: (project) ->
|
||||
# TODO: ends up getting done twice, since the URL is modified and the @project is modified. So don't do this, just set project directly... (?)
|
||||
return if project is @project
|
||||
url = @getURL()
|
||||
url += '&project=' unless /project=/.test url
|
||||
|
|
|
@ -88,7 +88,7 @@ _.extend LevelSessionSchema.properties,
|
|||
type: 'boolean' # Not tracked any more
|
||||
frame:
|
||||
type: 'number' # Not tracked any more
|
||||
thangs:
|
||||
thangs: # ... what is this? Is this used?
|
||||
type: 'object'
|
||||
additionalProperties:
|
||||
title: 'Thang'
|
||||
|
@ -241,7 +241,7 @@ _.extend LevelSessionSchema.properties,
|
|||
description: 'The date a match was computed.'
|
||||
playtime:
|
||||
title: 'Playtime so far'
|
||||
description: 'The total seconds of playtime on this session when the match was computed.'
|
||||
description: 'The total seconds of playtime on this session when the match was computed. Not currently tracked.'
|
||||
type: 'number'
|
||||
metrics:
|
||||
type: 'object'
|
||||
|
|
|
@ -206,10 +206,11 @@ module.exports = class Handler
|
|||
return @sendForbiddenError(res)
|
||||
|
||||
getById: (req, res, id) ->
|
||||
# return @sendNotFoundError(res) # for testing
|
||||
return @sendForbiddenError(res) unless @hasAccess(req)
|
||||
|
||||
@getDocumentForIdOrSlug id, (err, document) =>
|
||||
if req.query.project
|
||||
projection = {}
|
||||
projection[field] = 1 for field in req.query.project.split(',')
|
||||
@getDocumentForIdOrSlug id, projection, (err, document) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless document?
|
||||
return @sendForbiddenError(res) unless @hasAccessToDocument(req, document)
|
||||
|
@ -491,14 +492,18 @@ module.exports = class Handler
|
|||
|
||||
@isID: (id) -> _.isString(id) and id.length is 24 and id.match(/[a-f0-9]/gi)?.length is 24
|
||||
|
||||
getDocumentForIdOrSlug: (idOrSlug, done) ->
|
||||
getDocumentForIdOrSlug: (idOrSlug, projection, done) ->
|
||||
unless done
|
||||
done = projection # projection is optional argument
|
||||
projection = null
|
||||
idOrSlug = idOrSlug+''
|
||||
if Handler.isID(idOrSlug)
|
||||
@modelClass.findById(idOrSlug).exec (err, document) ->
|
||||
done(err, document)
|
||||
query = @modelClass.findById(idOrSlug)
|
||||
else
|
||||
@modelClass.findOne {slug: idOrSlug}, (err, document) ->
|
||||
done(err, document)
|
||||
query = @modelClass.findOne {slug: idOrSlug}
|
||||
query.select projection if projection
|
||||
query.exec (err, document) ->
|
||||
done(err, document)
|
||||
|
||||
doWaterfallChecks: (req, document, done) ->
|
||||
return done(null, document) unless @waterfallFunctions.length
|
||||
|
|
|
@ -158,7 +158,8 @@ LevelHandler = class LevelHandler extends Handler
|
|||
majorVersion: level.version.major
|
||||
creator: req.user._id+''
|
||||
|
||||
query = Session.find(sessionQuery).select('-screenshot')
|
||||
query = Session.find(sessionQuery).select('-screenshot -transpiledCode')
|
||||
# TODO: take out "code" as well, since that can get huge containing the transpiled code for the lat hero, and find another way of having the LadderSubmissionViews in the MyMatchesTab determine rankin readiness
|
||||
query.exec (err, results) =>
|
||||
if err then @sendDatabaseError(res, err) else @sendSuccess res, results
|
||||
|
||||
|
|
|
@ -527,11 +527,11 @@ updateMatchesInSession = (matchObject, sessionID, callback) ->
|
|||
opponentsArray = _.toArray opponentsClone
|
||||
currentMatchObject.opponents = opponentsArray
|
||||
currentMatchObject.codeLanguage = matchObject.opponents[opponentsArray[0].sessionID].codeLanguage
|
||||
currentMatchObject.simulator = @clientResponseObject.simulator
|
||||
currentMatchObject.randomSeed = parseInt(@clientResponseObject.randomSeed or 0, 10)
|
||||
#currentMatchObject.simulator = @clientResponseObject.simulator # Uncomment when actively debugging simulation mismatches
|
||||
#currentMatchObject.randomSeed = parseInt(@clientResponseObject.randomSeed or 0, 10) # Uncomment when actively debugging simulation mismatches
|
||||
LevelSession.findOne {'_id': sessionID}, (err, session) ->
|
||||
session = session.toObject()
|
||||
currentMatchObject.playtime = session.playtime ? 0
|
||||
#currentMatchObject.playtime = session.playtime ? 0 # Not useful if we can only see last 200
|
||||
sessionUpdateObject =
|
||||
$push: {matches: {$each: [currentMatchObject], $slice: -200}}
|
||||
#log.info "Updating session #{sessionID}"
|
||||
|
|
Loading…
Reference in a new issue