diff --git a/queries.lp b/queries.lp index 0414b770..9db33cba 100644 --- a/queries.lp +++ b/queries.lp @@ -165,6 +165,7 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r') Type Domain Client + Delay @@ -175,6 +176,7 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r') Type Domain Client + Delay diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 4be81386..6067fabe 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -208,6 +208,24 @@ function parseQueryStatus(data) { }; } +function formatReplyTime(data, type) { + const replyTime = data.reply.time; + if (type === "display") { + // Units: + // - seconds if replytime >= 1 second + // - milliseconds if reply time >= 100 µs + // - microseconds otherwise + return replyTime < 1e-4 + ? (1e6 * replyTime).toFixed(1) + " µs" + : replyTime < 1 + ? (1e3 * replyTime).toFixed(1) + " ms" + : replyTime.toFixed(1) + " s"; + } + + // else: return the number itself (for sorting and searching) + return replyTime; +} + function formatInfo(data) { // DNSSEC status var dnssecStatus = data.dnssec, @@ -306,11 +324,7 @@ function formatInfo(data) { if (data.reply.type !== "UNKNOWN") { replyInfo = divStart + "Reply:  " + data.reply.type; if (data.reply.time >= 0 && data.reply.type !== "UNKNOWN") { - replyInfo += - " (" + - (data.reply.time < 1 - ? (1e3 * data.reply.time).toFixed(1) + " ms)" - : data.reply.time.toFixed(1) + " s)"); + replyInfo += " (" + formatReplyTime(data, "display") + ")"; } replyInfo += ""; @@ -515,9 +529,10 @@ $(function () { }, }, { data: "status", width: "1%" }, - { data: "type", width: "5%" }, + { data: "type", width: "1%" }, { data: "domain", width: "45%" }, - { data: "client.ip", width: "29%", type: "ip-address", render: $.fn.dataTable.render.text() }, + { data: "client.ip", width: "29%", type: "ip-address" }, + { data: null, width: "4%", render: formatReplyTime }, { data: null, width: "10%", sortable: false, searchable: false }, ], lengthMenu: [ @@ -569,7 +584,7 @@ $(function () { } if (querystatus.buttontext !== false) { - $("td:eq(5)", row).html(querystatus.buttontext); + $("td:eq(6)", row).html(querystatus.buttontext); } }, });