perf: reduce background return latency via session caching and async map rendering
This commit is contained in:
@ -44,7 +44,7 @@ async function dispatchRefocus(reason: string) {
|
|||||||
const timeoutMs = 5000
|
const timeoutMs = 5000
|
||||||
|
|
||||||
const refreshWithTimeout = Promise.race([
|
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) =>
|
new Promise((_, reject) =>
|
||||||
setTimeout(() => reject(new Error("Auth refresh timeout")), timeoutMs)
|
setTimeout(() => reject(new Error("Auth refresh timeout")), timeoutMs)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -48,9 +48,9 @@ export const useRouteStore = defineStore('route', () => {
|
|||||||
// Si estamos en background, podemos sobreescribir la carga sin mostrar spinner
|
// Si estamos en background, podemos sobreescribir la carga sin mostrar spinner
|
||||||
if (isLoadingRoutes.value && !isBackground) return;
|
if (isLoadingRoutes.value && !isBackground) return;
|
||||||
|
|
||||||
// Si no forzamos, no hay filtros raros, ya tenemos rutas y aún no expira el caché, omitir llamada
|
// 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.
|
// Se respeta en background también porque descargar docenas de rutas traba el Javascript en móviles.
|
||||||
if (!force && !isBackground && !filters && allRoutes.value.length > 0 && (now - lastFetched.value < CACHE_TIME)) {
|
if (!force && !filters && allRoutes.value.length > 0 && (now - lastFetched.value < CACHE_TIME)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -136,10 +136,13 @@ function closePromoModal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchData(isBackground = false) {
|
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),
|
routeStore.loadRoutes(undefined, false, isBackground),
|
||||||
couponStore.loadCoupons({ active_only: true }, isBackground)
|
couponStore.loadCoupons({ active_only: true }, isBackground)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Update super-urgente, dibuja los buses actuales en el mapa al instante
|
||||||
updateActiveUnits();
|
updateActiveUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user