perf: optimize splash screen loading time (parallel map data + JWT role extraction instead of db query)
This commit is contained in:
@ -69,13 +69,9 @@ async function navigate() {
|
||||
return
|
||||
}
|
||||
|
||||
const { data: profile } = await supabase
|
||||
.from('users')
|
||||
.select('role')
|
||||
.eq('id', session.user.id)
|
||||
.single()
|
||||
|
||||
const role = profile?.role?.toUpperCase()
|
||||
// Get the role directly from the JWT to avoid slow database queries
|
||||
const role = session.user?.user_metadata?.role?.toUpperCase() || 'PASSENGER'
|
||||
|
||||
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'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user