Browse Source

Fix painel polling: 304 responses, logo re-fetches, and overlapping requests

- @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 <noreply@anthropic.com>
rate-limiter-2026
Edward Ribeiro 6 days ago
parent
commit
dba535f396
  1. 6
      sapl/templates/painel/index.html

6
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
})
})();
});

Loading…
Cancel
Save