fix: prevent multiple concurrent fetches in updateSystemList function

fix: correctly reset isFetchingSystems flag in updateSystemList function
This commit is contained in:
ompathak2004
2025-02-06 04:23:42 +05:30
committed by Henry Dollman
parent 58085bf300
commit 5b478c11eb

View File

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