refactor: updateSystemList function

This commit is contained in:
Henry Dollman
2025-02-05 20:21:57 -05:00
parent 5b478c11eb
commit f4480c7aa7

View File

@@ -42,33 +42,28 @@ const verifyAuth = () => {
}) })
} }
let isFetchingSystems = false; export const updateSystemList = (() => {
let isFetchingSystems = false
return async () => {
if (isFetchingSystems) {
return
}
isFetchingSystems = true
try {
const records = await pb
.collection<SystemRecord>("systems")
.getFullList({ sort: "+name", fields: "id,name,host,info,status" })
export const updateSystemList = async () => { if (records.length) {
$systems.set(records)
if (isFetchingSystems) return; } else {
isFetchingSystems = true verifyAuth()
}
try { } finally {
const records = await pb isFetchingSystems = false
.collection<SystemRecord>("systems") }
.getFullList({ sort: "+name", fields: "id,name,host,info,status" });
if (records.length) {
$systems.set(records);
} else {
verifyAuth();
}
} catch (e: any) {
// Suppressing pocketbase auto-cancellation error
if (e.isAbort || e.status === 0) {
return;
}
} finally {
isFetchingSystems = false
} }
}; })()
export const updateAlerts = () => { export const updateAlerts = () => {