update fetch api

This commit is contained in:
bagus-arie05
2026-01-29 08:44:18 +07:00
parent 2bf38e0f63
commit cccefb0775
4 changed files with 40 additions and 14 deletions
+21
View File
@@ -18,6 +18,9 @@ export const useQueueStore = defineStore('queue', () => {
const apiPatientsPerLoket = ref({});
const isLoadingPatients = ref(false);
const apiPatientsError = ref(null);
// Throttle mechanism: track last fetch time per loket
const lastFetchTime = ref({});
/**
* Sync patient status to apiPatientsPerLoket for reactivity
@@ -186,6 +189,24 @@ export const useQueueStore = defineStore('queue', () => {
isLoadingPatients.value = true;
apiPatientsError.value = null;
// THROTTLE: Check if we recently fetched (within last 5 seconds)
const now = Date.now();
const lastFetch = lastFetchTime.value[loketId] || 0;
const timeSinceLastFetch = now - lastFetch;
if (timeSinceLastFetch < 5000 && apiPatientsPerLoket.value[loketId]) {
console.log(`⏭️ [queueStore] Skipping fetch for loket ${loketId} (last fetched ${Math.round(timeSinceLastFetch/1000)}s ago)`);
isLoadingPatients.value = false;
return {
success: true,
message: 'Using cached data',
data: apiPatientsPerLoket.value[loketId]
};
}
// Update last fetch time
lastFetchTime.value[loketId] = now;
// Check for daily reset before fetching
checkAndResetDaily();