# HG changeset patch # User Mads Kiilerich # Date 1412288436 -7200 # Node ID dbd2f289158517640adab34f019c821f9811e5aa # Parent 0ece1a4cf6e3972036b17ee7efc0875375dff2c0 pull requests: abort pending ajax requests before starting new one Quick navigation and different load times could cause an old result to overwrite a new one. diff -r 0ece1a4cf6e3 -r dbd2f2891585 kallithea/public/js/base.js --- a/kallithea/public/js/base.js Fri Oct 03 00:20:36 2014 +0200 +++ b/kallithea/public/js/base.js Fri Oct 03 00:20:36 2014 +0200 @@ -362,7 +362,7 @@ } $target.html(_TM['Loading ...']).css('opacity','0.3'); - $.ajax({url: url, data: args, headers: {'X-PARTIAL-XHR': '1'}, cache: false, dataType: 'html'}) + return $.ajax({url: url, data: args, headers: {'X-PARTIAL-XHR': '1'}, cache: false, dataType: 'html'}) .done(function(html) { $target.html(html); $target.css('opacity','1.0'); @@ -372,6 +372,8 @@ } }) .fail(function(jqXHR, textStatus, errorThrown) { + if (textStatus == "abort") + return; console.log('Ajax failure: ' + textStatus); $target.html('ERROR: {0}'.format(textStatus)); $target.css('opacity','1.0'); diff -r 0ece1a4cf6e3 -r dbd2f2891585 kallithea/templates/pullrequests/pullrequest.html --- a/kallithea/templates/pullrequests/pullrequest.html Fri Oct 03 00:20:36 2014 +0200 +++ b/kallithea/templates/pullrequests/pullrequest.html Fri Oct 03 00:20:36 2014 +0200 @@ -146,10 +146,16 @@ pyroutes.register('pullrequest_repo_info', "${url('pullrequest_repo_info',repo_name='%(repo_name)s')}", ['repo_name']); + var pendingajax = undefined; var otherrepoChanged = function(){ var repo_name = $('#other_repo').val(); - ajaxGET(pyroutes.url('pullrequest_repo_info', {"repo_name": repo_name}), + if (pendingajax) { + pendingajax.abort(); + pendingajax = undefined; + } + pendingajax = ajaxGET(pyroutes.url('pullrequest_repo_info', {"repo_name": repo_name}), function(o){ + pendingajax = undefined; var data = JSON.parse(o.responseText); $('#other_repo_desc').html(data.description); @@ -217,7 +223,12 @@ url = url.replace(k,rev_data[k]); } - asynchtml(url, $('#pull_request_overview'), function(o){ + if (pendingajax) { + pendingajax.abort(); + pendingajax = undefined; + } + pendingajax = asynchtml(url, $('#pull_request_overview'), function(o){ + pendingajax = undefined; var jsdata = eval('('+YUD.get('jsdata').innerHTML+')'); // TODO: just get json var r = new BranchRenderer('graph_canvas', 'graph_content_pr'); r.render(jsdata,100);