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