mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-27 00:58:55 +01:00
Queue all concurrent server requests, but discard the earliest pending requests if the queue gets full
This commit is contained in:
parent
35cbfeec09
commit
33759f0cd9
@ -84,7 +84,6 @@ var et2_dataview_controller = (function(){ "use strict"; return Class.extend({
|
|||||||
|
|
||||||
// Current concurrent requests we have
|
// Current concurrent requests we have
|
||||||
this._request_queue = [];
|
this._request_queue = [];
|
||||||
this._request_timeout = 0;
|
|
||||||
|
|
||||||
// Register the dataFetch callback
|
// Register the dataFetch callback
|
||||||
this._grid.setDataCallback(this._gridCallback, this);
|
this._grid.setDataCallback(this._gridCallback, this);
|
||||||
@ -203,7 +202,6 @@ var et2_dataview_controller = (function(){ "use strict"; return Class.extend({
|
|||||||
|
|
||||||
// Reset the request queue
|
// Reset the request queue
|
||||||
this._request_queue = [];
|
this._request_queue = [];
|
||||||
this._request_timeout = 0;
|
|
||||||
|
|
||||||
// Update the data
|
// Update the data
|
||||||
this.update();
|
this.update();
|
||||||
@ -493,17 +491,6 @@ var et2_dataview_controller = (function(){ "use strict"; return Class.extend({
|
|||||||
// Clear any still existing timer
|
// Clear any still existing timer
|
||||||
this._clearTimer();
|
this._clearTimer();
|
||||||
|
|
||||||
if(this._request_queue.length >= this.CONCURRENT_REQUESTS)
|
|
||||||
{
|
|
||||||
// Too many requests, wait until later
|
|
||||||
var self = this;
|
|
||||||
this._queueTimer = window.setTimeout(function () {
|
|
||||||
self._flushQueue(_isUpdate);
|
|
||||||
// Try again with increasing delay, to a max of 30s
|
|
||||||
}, Math.min(30000,ET2_DATAVIEW_FETCH_TIMEOUT*Math.pow( 2, this._request_timeout++)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark all elements in a radius of ET2_DATAVIEW_STEPSIZE
|
// Mark all elements in a radius of ET2_DATAVIEW_STEPSIZE
|
||||||
var marked = {};
|
var marked = {};
|
||||||
var r = _isUpdate ? 0 : Math.floor(ET2_DATAVIEW_STEPSIZE / 2);
|
var r = _isUpdate ? 0 : Math.floor(ET2_DATAVIEW_STEPSIZE / 2);
|
||||||
@ -614,6 +601,7 @@ var et2_dataview_controller = (function(){ "use strict"; return Class.extend({
|
|||||||
this._request_queue.push({
|
this._request_queue.push({
|
||||||
query: query,
|
query: query,
|
||||||
context: ctx,
|
context: ctx,
|
||||||
|
// Start pending, set to 1 when request sent
|
||||||
status: 0
|
status: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -636,21 +624,36 @@ var et2_dataview_controller = (function(){ "use strict"; return Class.extend({
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Reset timeout timer
|
|
||||||
this._request_timeout = 0;
|
// Keep at least 1 previous pending
|
||||||
|
var keep = 1;
|
||||||
|
|
||||||
// The most recent is the one the user's most interested in
|
// The most recent is the one the user's most interested in
|
||||||
var request = null;
|
var request = null;
|
||||||
for(var i = this._request_queue.length - 1; i >= 0; i--)
|
for(var i = this._request_queue.length - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if(this._request_queue[i].status == 0)
|
// Only interested in pending requests (status 0)
|
||||||
|
if(this._request_queue[i].status != 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(request == null)
|
||||||
{
|
{
|
||||||
request = this._request_queue[i];
|
request = this._request_queue[i];
|
||||||
break;
|
}
|
||||||
|
else if (keep > 0)
|
||||||
|
{
|
||||||
|
keep--;
|
||||||
|
}
|
||||||
|
else if (keep <= 0)
|
||||||
|
{
|
||||||
|
// Cancel pending, they've probably scrolled past.
|
||||||
|
this._request_queue.splice(i,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(request == null) return;
|
if(request == null) return;
|
||||||
|
|
||||||
|
// Request being sent
|
||||||
request.status = 1;
|
request.status = 1;
|
||||||
|
|
||||||
// Call the callback
|
// Call the callback
|
||||||
|
Loading…
Reference in New Issue
Block a user