Improve speed of search (#1117)

* Stop searching empty fields

* Cache searchable fields to speed up future searches
This commit is contained in:
Tim Wilkinson 2024-03-22 17:49:59 -07:00 committed by GitHub
parent 43a4940032
commit b1c85fa281
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 22 deletions

View File

@ -484,7 +484,7 @@ html.print([[
</style>
<script>
let searchPending;
let cFilter;
let cFilter = "";
function doSearch() {
clearTimeout(searchPending);
searchPending = setTimeout(function() {
@ -510,8 +510,12 @@ html.print([[
else {
for (let i = 0; i < tds.length; i++) {
const td = tds[i];
const txt = td.textContent || td.innerText;
if (txt.toUpperCase().indexOf(filter) === -1) {
let txt = td.dataset.search;
if (txt === undefined) {
txt = (td.textContent || td.innerText).toUpperCase();
td.dataset.search = txt
}
if (txt.indexOf(filter) === -1) {
td.classList.add("nf");
td.parentElement.classList.add("nf");
}
@ -609,13 +613,13 @@ if next(localhosts) then
do
if first then
first = false
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td class='s f'>" .. v .. "</td></tr>"
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='f'></td><td class='s f'>" .. v .. "</td></tr>"
end
end
else
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td class='s f'></td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td class='f'></td></tr>"
end
for _, dmzhost in ipairs(host.hosts)
@ -649,13 +653,13 @@ if next(localhosts) then
do
if first then
first = false
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'>" .. localpart .. "</td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='s f'>" .. localpart .. "</td><td class='s f'>" .. v .. "</td></tr>"
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='f'></td><td class='s f'>" .. v .. "</td></tr>"
end
end
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'>" .. localpart .. "</td><td class='s f'></td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='s f'>" .. localpart .. "</td><td class='f'></td></tr>"
end
end
end
@ -821,13 +825,13 @@ do
do
if first then
first = false
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td>" .. c3 .. "</td><td>" .. c4 .. "</td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td>" .. c5 .. "</td><td>" .. c5b .. "</td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td>" .. c3 .. "</td><td>" .. c4 .. "</td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td>" .. c5 .. "</td><td>" .. c5b .. "</td><td class='s f'>" .. v .. "</td></tr>"
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'></td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='f'></td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
end
end
else
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td>" .. c3 .. "</td><td>" .. c4 .. "</td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td>" .. c5 .. "</td><td>" .. c5b .. "</td><td class='s f'></td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td>" .. c3 .. "</td><td>" .. c4 .. "</td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td>" .. c5 .. "</td><td>" .. c5b .. "</td><td class='f'></td></tr>"
end
if host then
@ -841,13 +845,13 @@ do
do
if first then
first = false
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'></td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='f'></td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
end
end
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td></td><td></td><td></td><td></td><td class='s f'></td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td></td><td></td><td></td><td></td><td class='f'></td></tr>"
end
end
end
@ -911,7 +915,7 @@ do
c5b = math.ceil(track.distance * 0.001) .. " km"
end
end
local tbody = "<tbody><tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td></td><td></td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td></td><td>" .. c5b .. "</td><td class='s f'></td></tr></tbody>"
local tbody = "<tbody><tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td></td><td></td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td></td><td>" .. c5b .. "</td><td class='f'></td></tr></tbody>"
rows[#rows + 1] = { key = name:lower(), row = tbody }
end
end
@ -1042,13 +1046,13 @@ do
do
if first then
first = false
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td>" .. c3 .. "</td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td>" .. c3 .. "</td><td></td><td class='s f'>" .. v .. "</td></tr>"
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='f'></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
end
end
else
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td>" .. c3 .. "</td><td></td><td class='s f'></td></tr>"
tbody = tbody .. "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='f'></td><td>" .. c3 .. "</td><td></td><td class='f'></td></tr>"
end
for _, dmzhost in ipairs(host.hosts)
@ -1061,13 +1065,13 @@ do
do
if first then
first = false
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='f'></td><td></td><td></td><td class='s f'>" .. v .. "</td></tr>"
end
end
else
tbody = tbody .. "<tr class=s><td class='s f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td class='s f'></td></tr>"
tbody = tbody .. "<tr class=s><td class='f'></td><td class='s f'>" .. localpart .. "</td><td></td><td></td><td class='f'></td></tr>"
end
end
end