perf: reduce background return latency via session caching and async map rendering

This commit is contained in:
2026-03-04 10:43:58 -05:00
parent 90bb93be17
commit b89de437b2
3 changed files with 8 additions and 5 deletions

View File

@ -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)
)

View File

@ -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
}

View File

@ -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();
}