From b89de437b2f6c3174751ecefebdb41193d3a8241 Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Wed, 4 Mar 2026 10:43:58 -0500 Subject: [PATCH] perf: reduce background return latency via session caching and async map rendering --- frontend/src/App.vue | 2 +- frontend/src/stores/route.ts | 6 +++--- frontend/src/views/MapView.vue | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index e38bbf6..4aed456 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -44,7 +44,7 @@ async function dispatchRefocus(reason: string) { const timeoutMs = 5000 const refreshWithTimeout = Promise.race([ - supabase.auth.refreshSession(), + supabase.auth.getSession(), // Usa caché interno si el token no ha expirado, previene delays innecesarios HTTP de 1-3 segundos new Promise((_, reject) => setTimeout(() => reject(new Error("Auth refresh timeout")), timeoutMs) ) diff --git a/frontend/src/stores/route.ts b/frontend/src/stores/route.ts index f65b24b..06aee63 100644 --- a/frontend/src/stores/route.ts +++ b/frontend/src/stores/route.ts @@ -48,9 +48,9 @@ export const useRouteStore = defineStore('route', () => { // Si estamos en background, podemos sobreescribir la carga sin mostrar spinner if (isLoadingRoutes.value && !isBackground) return; - // Si no forzamos, no hay filtros raros, ya tenemos rutas y aún no expira el caché, omitir llamada - // Excepción: isBackground de refocus obliga a actualizar para asegurar frescura después de mucho rato apagado. - if (!force && !isBackground && !filters && allRoutes.value.length > 0 && (now - lastFetched.value < CACHE_TIME)) { + // Si no forzamos, no hay filtros raros, ya tenemos rutas y aún no expira el caché, omitir llamada. + // Se respeta en background también porque descargar docenas de rutas traba el Javascript en móviles. + if (!force && !filters && allRoutes.value.length > 0 && (now - lastFetched.value < CACHE_TIME)) { return } diff --git a/frontend/src/views/MapView.vue b/frontend/src/views/MapView.vue index f0f8d5e..6c94de5 100644 --- a/frontend/src/views/MapView.vue +++ b/frontend/src/views/MapView.vue @@ -136,10 +136,13 @@ function closePromoModal() { } async function fetchData(isBackground = false) { - await Promise.all([ + // Estas son actualizaciones asíncronas no urgentes para render principal + Promise.all([ routeStore.loadRoutes(undefined, false, isBackground), couponStore.loadCoupons({ active_only: true }, isBackground) ]); + + // Update super-urgente, dibuja los buses actuales en el mapa al instante updateActiveUnits(); }