update fetch api
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user