mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-28 22:00:25 -04:00
Reduced unnecessary name fetching.
This commit is contained in:
parent
3e82e0b599
commit
2d32bc1ac4
2 changed files with 13 additions and 4 deletions
app/views/play/ladder
|
@ -74,6 +74,10 @@ class LeaderboardData
|
|||
# @playersBelow.once 'sync', @leaderboardPartLoaded, @
|
||||
|
||||
leaderboardPartLoaded: ->
|
||||
# Forget loading the up-to-date names, that's way too slow for something that refreshes all the time, we learned.
|
||||
@loaded = true
|
||||
@trigger 'sync'
|
||||
return
|
||||
if @session
|
||||
if @topPlayers.loaded # and @playersAbove.loaded and @playersBelow.loaded
|
||||
@loaded = true
|
||||
|
|
|
@ -14,23 +14,28 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
|
||||
constructor: (options, @level, @sessions) ->
|
||||
super(options)
|
||||
@nameMap = {}
|
||||
@refreshMatches()
|
||||
|
||||
refreshMatches: ->
|
||||
@teams = teamDataFromLevel @level
|
||||
@nameMap = {}
|
||||
@loadNames()
|
||||
|
||||
loadNames: ->
|
||||
# Only fetch the names for the userIDs we don't already have in @nameMap
|
||||
ids = []
|
||||
for session in @sessions.models
|
||||
ids.push match.opponents[0].userID for match in session.get('matches') or []
|
||||
for match in (session.get('matches') or [])
|
||||
id = match.opponents[0].userID
|
||||
ids.push id unless @nameMap[id]
|
||||
|
||||
success = (@nameMap) =>
|
||||
return @finishRendering() unless ids.length
|
||||
|
||||
success = (nameMap) =>
|
||||
for session in @sessions.models
|
||||
for match in session.get('matches') or []
|
||||
opponent = match.opponents[0]
|
||||
opponent.userName = @nameMap[opponent.userID]
|
||||
@nameMap[opponent.userID] = nameMap[opponent.userID]
|
||||
@finishRendering()
|
||||
|
||||
$.ajax('/db/user/-/names', {
|
||||
|
|
Loading…
Add table
Reference in a new issue