From 372a2b34c8c3f4eeb12ac3686da7763a6ed121b2 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Mon, 27 May 2013 03:19:51 +0100 Subject: [PATCH] don't resolve more than 15 names in one request - this is approximately the limit imposed by the server if more are to be resolved, multiple requests are made. this does increase the odds of hitting the request rate limit, but in that case we'll get http failed requests and the names will be pushed back onto the pending resolve list for next time fix #323 --- code/player_names.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/code/player_names.js b/code/player_names.js index 5818db79..1ad0183c 100644 --- a/code/player_names.js +++ b/code/player_names.js @@ -11,7 +11,6 @@ window.getPlayerName = function(guid) { if(localStorage[guid]) return localStorage[guid]; // only add to queue if it isn’t already if(playersToResolve.indexOf(guid) === -1 && playersInResolving.indexOf(guid) === -1) { - console.log('resolving player guid=' + guid); playersToResolve.push(guid); } return '{'+guid.slice(0, 12)+'}'; @@ -40,18 +39,38 @@ window.playerNameToGuid = function(playerName) { // get replaced by their correct versions. window.resolvePlayerNames = function() { if(window.playersToResolve.length === 0) return; - var p = window.playersToResolve; + + //limit per request. stock site is never more than 13 (8 res, 4 mods, owner) + //testing shows 15 works and 20 fails + var MAX_RESOLVE_PLAYERS_PER_REQUEST = 15; + + var p = window.playersToResolve.slice(0,MAX_RESOLVE_PLAYERS_PER_REQUEST); + window.playersToResolve = playersToResolve.slice(MAX_RESOLVE_PLAYERS_PER_REQUEST); + var d = {guids: p}; - playersInResolving = window.playersInResolving.concat(p); - playersToResolve = []; + window.playersInResolving = window.playersInResolving.concat(p); + postAjax('getPlayersByGuids', d, function(dat) { - $.each(dat.result, function(ind, player) { - window.setPlayerName(player.guid, player.nickname); - // remove from array - window.playersInResolving.splice(window.playersInResolving.indexOf(player.guid), 1); - }); + if(dat.result) { + $.each(dat.result, function(ind, player) { + window.setPlayerName(player.guid, player.nickname); + // remove from array + window.playersInResolving.splice(window.playersInResolving.indexOf(player.guid), 1); + }); + } else { + //no 'result' - a successful http request, but the returned result was an error of some kind + console.warn('getplayers problem - no result in response: '+dat); + + //likely to be some kind of 'bad request' (e.g. too many names at once, or otherwise badly formatted data. + //therefore, not a good idea to automatically retry by adding back to the playersToResolve list + } + + //TODO: have an event triggered for this instead of hard-coded single function call if(window.selectedPortal) window.renderPortalDetails(window.selectedPortal); + + //if more to do, run again + if(window.playersToResolve.length>0) resolvePlayerNames(); }, function() { // append failed resolves to the list again