Skip to content

Commit

Permalink
Fix possible race condition on page load of the index page. This is a…
Browse files Browse the repository at this point in the history
… recent regression

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Jul 1, 2024
1 parent 330845b commit bfa3906
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scripts/pi-hole/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ function updateTopLists() {
}

var previousCount = 0;
var firstSummaryUpdate = true;
function updateSummaryData(runOnce = false) {
$.getJSON("/api/stats/summary", function (data) {
var intl = new Intl.NumberFormat();
Expand All @@ -411,8 +412,11 @@ function updateSummaryData(runOnce = false) {
$("span#percent_blocked").text(formattedPercentage);
$("span#gravity_size").text(intl.format(parseInt(data.gravity.domains_being_blocked, 10)));

if (2 * previousCount < newCount && newCount > 100) {
if (2 * previousCount < newCount && newCount > 100 && !firstSummaryUpdate) {
// Update the charts if the number of queries has increased significantly
// Do not run this on the first update as reloading the same data after
// creating the charts happens asynchronously and can cause a race
// condition
updateQueriesOverTime();
updateClientsOverTime();
updateQueryTypesPie();
Expand All @@ -421,6 +425,7 @@ function updateSummaryData(runOnce = false) {
}

previousCount = newCount;
firstSummaryUpdate = false;
})
.done(function () {
if (!runOnce) utils.setTimer(updateSummaryData, REFRESH_INTERVAL.summary);
Expand Down

0 comments on commit bfa3906

Please sign in to comment.