perf: optimize splash screen loading time (parallel map data + JWT role extraction instead of db query)

This commit is contained in:
2026-02-25 23:25:07 -05:00
parent f38f99a4c3
commit 528e3989ef

View File

@ -69,13 +69,9 @@ async function navigate() {
return
}
const { data: profile } = await supabase
.from('users')
.select('role')
.eq('id', session.user.id)
.single()
// Get the role directly from the JWT to avoid slow database queries
const role = session.user?.user_metadata?.role?.toUpperCase() || 'PASSENGER'
const role = profile?.role?.toUpperCase()
if (role === 'ADMIN') router.replace('/admin')
else if (role === 'DRIVER') router.replace('/driver')
else if (role === 'PROMOTER') router.replace('/promoter')
@ -83,13 +79,17 @@ async function navigate() {
}
async function performInitializationTasks() {
statusMessage.value = 'Verificando sesión...'
statusMessage.value = 'Verificando datos...'
statusMessage.value = 'Cargando datos de rutas...'
try { await routeStore.loadRoutes() } catch (e) { console.error(e) }
statusMessage.value = 'Cargando paradas...'
try { await busStopStore.loadBusStops() } catch (e) { console.error(e) }
// Load essential map data in parallel to save time
try {
await Promise.all([
routeStore.loadRoutes(),
busStopStore.loadBusStops()
])
} catch (e) {
console.error('Error pre-loading map data', e)
}
statusMessage.value = 'Listo para usar'
}