From 12e0ce2f4c8aba2edb35f833ea54f96e68490d9a Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 4 Jul 2019 22:50:00 -0400 Subject: [PATCH] Improve audit logic to batch requests. Signed-off-by: Daniel --- scripts/pi-hole/js/auditlog.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js index 3aa9912c..52790602 100644 --- a/scripts/pi-hole/js/auditlog.js +++ b/scripts/pi-hole/js/auditlog.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ // Define global variables -var timeLineChart, queryTypeChart, forwardDestinationChart; +var timeLineChart, queryTypeChart, forwardDestinationChart, auditList = [], auditTimeout; // Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406 function escapeHtml(text) { @@ -96,7 +96,7 @@ $(document).ready(function() { } else { - add(url,"audit"); + auditUrl(url); } }); @@ -109,11 +109,27 @@ $(document).ready(function() { } else { - add(url,"audit"); + auditUrl(url); } }); }); +function auditUrl(url) { + if (auditList.indexOf(url) > -1) { + return; + } + if (auditTimeout) { + clearTimeout(auditTimeout); + } + auditList.push(url); + // wait 3 seconds to see if more domains need auditing + // and batch them all into a single request + auditTimeout = setTimeout(function() { + add(auditList.join(' '), "audit"); + auditList = []; + }, 3000); +} + $("#gravityBtn").on("click", function() { window.location.replace("gravity.php?go");