From db641dccb68ae3ff0bdd70dc7d60dc9605fe31c0 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Thu, 30 Apr 2015 12:54:29 +0300 Subject: [PATCH] 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 ca090378b4875afebdebd67bdb457eebad6b2b7d) 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 --- horizon/static/horizon/js/horizon.tables.js | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/horizon/static/horizon/js/horizon.tables.js b/horizon/static/horizon/js/horizon.tables.js index 17de8ea5a3..cf95a8d900 100644 --- a/horizon/static/horizon/js/horizon.tables.js +++ b/horizon/static/horizon/js/horizon.tables.js @@ -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); } }); });