From dba535f396df035ab4d97f5c32ebbb04a895c8f4 Mon Sep 17 00:00:00 2001 From: Edward Oliveira Date: Wed, 29 Apr 2026 13:34:34 -0300 Subject: [PATCH] Fix painel polling: 304 responses, logo re-fetches, and overlapping requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - @never_cache on get_dados_painel: ConditionalGetMiddleware was computing an ETag from the unchanged JsonResponse body and returning 304 with no body; the display always needs a live response. - Guard logo src update: jQuery .attr("src", ...) fired a browser HTTP GET on every 500 ms poll even when the URL hadn't changed — 120 media requests/min per user, hitting the auth_threshold and triggering user_blocked for painel operators. - Fix poll scheduling: setTimeout was evaluated at $.ajax options construction time, scheduling the next poll 500 ms after the request started rather than after it finished. Slow responses (>500 ms) stacked concurrent in-flight requests, creating a self-amplifying load loop and a DOM race condition where older responses could overwrite newer ones. Moved to a proper complete callback so at most one request is in-flight at any time. Co-Authored-By: Claude Sonnet 4.6 --- sapl/templates/painel/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sapl/templates/painel/index.html b/sapl/templates/painel/index.html index 523fa2423..2283c9c82 100644 --- a/sapl/templates/painel/index.html +++ b/sapl/templates/painel/index.html @@ -284,7 +284,7 @@ $('#tema_solene_div').show(); } - if (data["brasao"] != null) + if (data["brasao"] != null && $("#logo-painel").attr("src") !== data["brasao"]) $("#logo-painel").attr("src", data["brasao"]); var presentes = $("#parlamentares"); @@ -487,9 +487,9 @@ error: function(err) { console.error(err); }, + complete: function() { setTimeout(poll, 500); }, dataType: "json", - complete: setTimeout(function() {poll()}, 500), - timeout: 20000 // TODO: decrease + timeout: 20000 }) })(); });