Optimize dashboard overview loading

This commit is contained in:
2026-06-06 00:42:00 +02:00
parent a412998c96
commit b340489d96
14 changed files with 990 additions and 88 deletions

View File

@@ -89,11 +89,23 @@ export async function waitForVisible(ms) {
export async function apiFetch(path, options = {}) {
const url = path.startsWith("http") ? path : `${API}${path}`;
const timeout = options.timeout ?? FETCH_TIMEOUT;
const {timeout: _timeout, ...fetchOptions} = options;
const {timeout: _timeout, cache = "no-store", ...fetchOptions} = options;
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), timeout);
let timedOut = false;
const timer = setTimeout(() => {
timedOut = true;
ctrl.abort();
}, timeout);
try {
return await fetch(url, {cache: "no-store", ...fetchOptions, signal: ctrl.signal});
return await fetch(url, {cache, ...fetchOptions, signal: ctrl.signal});
} catch (error) {
if (timedOut || error?.name === "AbortError") {
const message = `Request timed out after ${Math.round(timeout / 1000)}s: ${url}`;
const timeoutError = new Error(message);
timeoutError.name = "TimeoutError";
throw timeoutError;
}
throw error;
} finally {
clearTimeout(timer);
}