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
This commit is contained in:
Jon Atkins
2013-05-27 03:19:51 +01:00
parent 9b8cac9e6f
commit 372a2b34c8

View File

@ -11,7 +11,6 @@ window.getPlayerName = function(guid) {
if(localStorage[guid]) return localStorage[guid];
// only add to queue if it isnt 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