perf(statuspages): page the monitor list and batch the group import
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m59s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Canceled after 1m1s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m59s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Canceled after 1m1s
With thousands of monitors on a status page the editor was tens of megabytes, as every row carried the options of all groups, and importing the monitor groups updated each monitor in its own statement. - The monitors of the editor are shown 50 at a time. All rows stay in the form, as saving replaces the page's monitors. - Rows carry their own group only and get the other options from the row template once shown or focused. - The filter matches a monitor's name and group path only, no longer the names of the groups in its select. - The import creates the groups one nesting level at a time and files all monitors in one statement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
383b63bc0e
commit
52d2ce25c9
10 files changed
+707
-340
No files matched your search
@@ -241,7 +241,7 @@
|
||||
if (checkAll) {
|
||||
const on = checkAll.dataset.checkAll === "on";
|
||||
checkAll.closest("form")?.querySelectorAll(checkAll.dataset.checkTarget).forEach((box) => {
|
||||
if (box.closest("[data-row]")?.hidden) return;
|
||||
if (box.closest("[data-row]")?.hasAttribute("data-filtered-out")) return;
|
||||
box.checked = on;
|
||||
if (on) addRowFields(box);
|
||||
});
|
||||
@@ -341,15 +341,72 @@
|
||||
if (ev.target.matches('[data-row] [data-field="include"]') && ev.target.checked) addRowFields(ev.target);
|
||||
});
|
||||
|
||||
// [data-filter-rows] hides the rows of the list it names whose text does
|
||||
// not contain what is typed.
|
||||
// Lists with data-page-size show that many of their rows at a time, of
|
||||
// those a filter leaves; the [data-row-pager] naming the list turns the
|
||||
// pages. The other rows stay in the DOM, so forms still send them.
|
||||
// Selects with data-lazy-options hold their chosen option only; the full
|
||||
// list comes from the form's row template once the row is shown or used.
|
||||
const fillOptions = (sel) => {
|
||||
const tpl = sel.closest("form")?.querySelector("template[data-row-fields]");
|
||||
const full = tpl?.content.querySelector(`select[data-field="${sel.dataset.field}"]`);
|
||||
if (!full) return;
|
||||
const value = sel.value;
|
||||
sel.replaceChildren(...[...full.options].map((o) => o.cloneNode(true)));
|
||||
sel.value = value;
|
||||
sel.removeAttribute("data-lazy-options");
|
||||
};
|
||||
document.addEventListener("focusin", (ev) => {
|
||||
if (ev.target.matches?.("select[data-lazy-options]")) fillOptions(ev.target);
|
||||
});
|
||||
const showRowPage = (list, page) => {
|
||||
const rows = [...list.querySelectorAll(":scope > [data-row]")];
|
||||
const size = Number(list.dataset.pageSize) || rows.length || 1;
|
||||
const shown = rows.filter((row) => !row.hasAttribute("data-filtered-out"));
|
||||
const pages = Math.max(1, Math.ceil(shown.length / size));
|
||||
page = Math.min(Math.max(0, page), pages - 1);
|
||||
list.dataset.page = String(page);
|
||||
for (const row of rows) row.hidden = true;
|
||||
for (const row of shown.slice(page * size, (page + 1) * size)) {
|
||||
row.hidden = false;
|
||||
row.querySelectorAll("select[data-lazy-options]").forEach(fillOptions);
|
||||
}
|
||||
for (const nav of document.querySelectorAll(`[data-row-pager="#${list.id}"]`)) {
|
||||
nav.hidden = pages < 2;
|
||||
nav.querySelector('[data-row-page="prev"]').disabled = page === 0;
|
||||
nav.querySelector('[data-row-page="next"]').disabled = page >= pages - 1;
|
||||
const status = nav.querySelector("[data-row-page-status]");
|
||||
if (status) {
|
||||
const values = {
|
||||
from: shown.length ? page * size + 1 : 0,
|
||||
to: Math.min((page + 1) * size, shown.length),
|
||||
total: shown.length,
|
||||
};
|
||||
status.textContent = status.dataset.template.replace(/\{(\w+)\}/g, (m, k) => values[k] ?? m);
|
||||
}
|
||||
}
|
||||
};
|
||||
for (const list of document.querySelectorAll("[data-page-size][id]")) showRowPage(list, 0);
|
||||
document.addEventListener("click", (ev) => {
|
||||
const btn = ev.target.closest("[data-row-page]");
|
||||
if (!btn) return;
|
||||
const list = document.querySelector(btn.closest("[data-row-pager]").dataset.rowPager);
|
||||
showRowPage(list, Number(list.dataset.page || 0) + (btn.dataset.rowPage === "next" ? 1 : -1));
|
||||
});
|
||||
|
||||
// [data-filter-rows] hides the rows of the list it names whose text, or
|
||||
// that of their [data-filter-text], does not contain what is typed.
|
||||
document.addEventListener("input", (ev) => {
|
||||
const input = ev.target.closest("[data-filter-rows]");
|
||||
if (!input) return;
|
||||
const needle = input.value.trim().toLowerCase();
|
||||
for (const row of document.querySelectorAll(input.dataset.filterRows + " > [data-row]")) {
|
||||
row.hidden = needle !== "" && !row.textContent.toLowerCase().includes(needle);
|
||||
const list = document.querySelector(input.dataset.filterRows);
|
||||
for (const row of list.querySelectorAll(":scope > [data-row]")) {
|
||||
const text = (row.querySelector("[data-filter-text]") ?? row).textContent;
|
||||
const out = needle !== "" && !text.toLowerCase().includes(needle);
|
||||
row.toggleAttribute("data-filtered-out", out);
|
||||
row.hidden = out;
|
||||
}
|
||||
if (list.dataset.pageSize) showRowPage(list, 0);
|
||||
});
|
||||
|
||||
// Only the settings of the selected check type are shown and submitted.
|
||||
|
||||
Reference in new issue
Block a user