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