perf: optimization phases 3-5

This commit is contained in:
2026-02-26 12:50:12 -05:00
parent 7b3141e5e9
commit 2dd3384882
6 changed files with 41 additions and 4 deletions

View File

@ -9,9 +9,13 @@ export const useBusStopStore = defineStore('busStop', () => {
const busStops = ref<BusStop[]>([])
const isLoading = ref(false)
const error = ref<string | null>(null)
const lastFetched = ref<number>(0)
async function loadBusStops(force = false) {
if (!force && busStops.value.length > 0) {
const CACHE_TIME = 1000 * 60 * 30; // 30 minutos
const now = Date.now();
if (!force && busStops.value.length > 0 && (now - lastFetched.value < CACHE_TIME)) {
return
}
@ -19,6 +23,7 @@ export const useBusStopStore = defineStore('busStop', () => {
error.value = null
try {
busStops.value = await busStopsService.getAllBusStops()
lastFetched.value = now;
} catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to load bus stops'
console.error('Error loading bus stops:', e)