Fix exponentially growing AJAX updates for table rows

Schedule next table rows update only when the last row was
updated. Since unit-test for this fix relies on a blueprint
replace-qunit-tests-with-jasmine it is moved to a separate commit to
speed up this fix merge, see https://review.openstack.org/#/c/179013/

Closes-Bug: #1263665
(cherry picked from commit ca090378b4)

Conflict Resolution Notes:
cherry-pick needed to have the old body of the complete: function
manually removed - it wasn't sure if it still belonged (resulting in
nearly duplicate code) or should be removed. I'm a bit surprised the
cherry-pick didn't auto-resolve.

Conflicts:
	horizon/static/horizon/js/horizon.tables.js

Change-Id: Id603a4fde5713d8f2b85b1dcf72c82c93a87c755
This commit is contained in:
Timur Sufiev 2015-04-30 12:54:29 +03:00 committed by Doug Fish
parent 97f9d78451
commit db641dccb6
1 changed files with 18 additions and 14 deletions

View File

@ -1,8 +1,9 @@
/* Namespace for core functionality related to DataTables. */
horizon.datatables = {
update: function () {
var $rows_to_update = $('tr.status_unknown.ajax-update');
if ($rows_to_update.length) {
var $rows_to_update = $('tr.status_unknown.ajax-update'),
rows_to_update = $rows_to_update.length;
if ( rows_to_update > 0 ) {
var interval = $rows_to_update.attr('data-update-interval'),
$table = $rows_to_update.closest('table'),
decay_constant = $table.attr('decay_constant');
@ -91,19 +92,22 @@ horizon.datatables = {
complete: function (jqXHR, textStatus) {
// Revalidate the button check for the updated table
horizon.datatables.validate_button();
// Set interval decay to this table, and increase if it already exist
if(decay_constant === undefined) {
decay_constant = 1;
} else {
decay_constant++;
rows_to_update--;
// Schedule next poll when all the rows are updated
if ( rows_to_update === 0 ) {
// Set interval decay to this table, and increase if it already exist
if(decay_constant === undefined) {
decay_constant = 1;
} else {
decay_constant++;
}
$table.attr('decay_constant', decay_constant);
// Poll until there are no rows in an "unknown" state on the page.
var next_poll = interval * decay_constant;
// Limit the interval to 30 secs
if(next_poll > 30 * 1000) { next_poll = 30 * 1000; }
setTimeout(horizon.datatables.update, next_poll);
}
$table.attr('decay_constant', decay_constant);
// Poll until there are no rows in an "unknown" state on the page.
next_poll = interval * decay_constant;
// Limit the interval to 30 secs
if(next_poll > 30 * 1000) { next_poll = 30 * 1000; }
setTimeout(horizon.datatables.update, next_poll);
}
});
});