Reduced unnecessary name fetching.

This commit is contained in:
Nick Winter 2014-03-09 13:22:22 -07:00
parent 3e82e0b599
commit 2d32bc1ac4
2 changed files with 13 additions and 4 deletions

View file

@ -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

View file

@ -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', {