perf: optimize splash screen loading and remove unused telemetry code
This commit is contained in:
@ -44,16 +44,22 @@ onMounted(async () => {
|
||||
showLoading.value = true
|
||||
loadingVisible.value = true
|
||||
|
||||
// Short timeout for safety - app should be ready way before this
|
||||
const initTimeout = setTimeout(() => {
|
||||
console.warn('Initialization taking too long, forcing navigation...')
|
||||
statusMessage.value = 'Iniciando de todas formas...'
|
||||
navigate()
|
||||
}, 5000)
|
||||
}, 3000)
|
||||
|
||||
try {
|
||||
await performInitializationTasks()
|
||||
// Start all tasks in parallel: Session check + Data loading
|
||||
const [sessionData] = await Promise.all([
|
||||
supabase.auth.getSession(),
|
||||
performInitializationTasks()
|
||||
])
|
||||
|
||||
clearTimeout(initTimeout)
|
||||
navigate()
|
||||
navigate(sessionData.data.session)
|
||||
} catch (error) {
|
||||
console.error('Initialization failed', error)
|
||||
clearTimeout(initTimeout)
|
||||
@ -61,15 +67,16 @@ onMounted(async () => {
|
||||
}
|
||||
})
|
||||
|
||||
async function navigate() {
|
||||
const { data: { session } } = await supabase.auth.getSession()
|
||||
async function navigate(passedSession?: any) {
|
||||
// Use passed session or fetch if missing
|
||||
const session = passedSession || (await supabase.auth.getSession()).data.session
|
||||
|
||||
if (!session) {
|
||||
router.replace('/map')
|
||||
return
|
||||
}
|
||||
|
||||
// Get the role directly from the JWT to avoid slow database queries
|
||||
// Get the role directly from user metadata for speed
|
||||
const role = session.user?.user_metadata?.role?.toUpperCase() || 'PASSENGER'
|
||||
|
||||
if (role === 'ADMIN') router.replace('/admin')
|
||||
@ -80,13 +87,16 @@ async function navigate() {
|
||||
|
||||
async function performInitializationTasks() {
|
||||
statusMessage.value = 'Verificando datos...'
|
||||
console.log('Starting initialization tasks...')
|
||||
|
||||
// Load essential map data in parallel to save time
|
||||
try {
|
||||
const start = Date.now()
|
||||
await Promise.all([
|
||||
routeStore.loadRoutes(),
|
||||
busStopStore.loadBusStops()
|
||||
routeStore.loadRoutes().then(() => console.log('Routes loaded')),
|
||||
busStopStore.loadBusStops().then(() => console.log('Bus stops loaded'))
|
||||
])
|
||||
console.log(`Initialization tasks finished in ${Date.now() - start}ms`)
|
||||
} catch (e) {
|
||||
console.error('Error pre-loading map data', e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user