@@ -15,7 +15,7 @@ import {useOverridenEventDescriptorProperties} from "@/state/useDevUtilities";
1515import { User } from "firebase/auth" ;
1616import { extractTalksFromSchedule , VoxxrinDailySchedule } from "@/models/VoxxrinSchedule" ;
1717import { VoxxrinDay } from "@/models/VoxxrinDay" ;
18- import { checkCache } from "@/services/Cachings" ;
18+ import { checkCache , preloadPicture } from "@/services/Cachings" ;
1919import { Temporal } from "temporal-polyfill" ;
2020import { CompletablePromiseQueue } from "@/models/utils" ;
2121import { prepareSchedules } from "@/state/useSchedule" ;
@@ -69,6 +69,31 @@ export function useConferenceDescriptor(
6969export const useSharedConferenceDescriptor = createSharedComposable ( useConferenceDescriptor ) ;
7070
7171
72+ async function prepareEventInfos ( user : User , confDescriptor : VoxxrinConferenceDescriptor , promisesQueue : CompletablePromiseQueue ) {
73+ PERF_LOGGER . debug ( ( ) => `prepareEventInfos(userId=${ user . uid } , eventId=${ confDescriptor . id . value } )` ) ;
74+
75+ await checkCache ( `offlineEventInfos(eventId=${ confDescriptor . id . value } )(floorPlans)` , Temporal . Duration . from ( { hours : 6 } ) , async ( ) => {
76+ PERF_LOGGER . debug ( ( ) => `offlineEventInfos(eventId=${ confDescriptor . id . value } )(floorPlans)` )
77+ promisesQueue . addAll (
78+ ( confDescriptor . infos ?. floorPlans || [ ] )
79+ . map ( floorPlan => ( ) => preloadPicture ( floorPlan . pictureUrl )
80+ ) , { priority : 1000 } )
81+ } ) ;
82+
83+ await checkCache ( `offlineEventInfos(eventId=${ confDescriptor . id . value } )(sponsorships)` , Temporal . Duration . from ( { hours : 24 } ) , async ( ) => {
84+ PERF_LOGGER . debug ( ( ) => `offlineEventInfos(eventId=${ confDescriptor . id . value } )(sponsorships)` )
85+ const sponsorships = ( confDescriptor . infos ?. sponsors || [ ] )
86+ . reduce (
87+ ( sponsorships , sponsorType ) => sponsorships . concat ( ...sponsorType . sponsorships ) ,
88+ [ ] as Array < { logoUrl : string } >
89+ ) ;
90+
91+ promisesQueue . addAll (
92+ sponsorships . map ( sponsorship => ( ) => preloadPicture ( sponsorship . logoUrl )
93+ ) , { priority : 1000 } )
94+ } ) ;
95+ }
96+
7297export function useOfflineEventPreparation (
7398 userRef : Ref < User | null | undefined > ,
7499 confDescriptorRef : Ref < VoxxrinConferenceDescriptor | undefined > ,
@@ -95,7 +120,7 @@ export function useOfflineEventPreparation(
95120 watchCleaner ( ) ;
96121
97122 await checkCache ( `useOfflineEventPreparation(eventId=${ confDescriptor . id . value } )` , Temporal . Duration . from ( { hours : 6 } ) , async ( ) => {
98- return new Promise ( schedulePreparationResolved => {
123+ return new Promise ( async schedulePreparationResolved => {
99124 const otherDayIds = availableDays . filter ( availableDay => ! availableDay . id . isSameThan ( currentSchedule . day ) ) . map ( d => d . id ) ;
100125 LOGGER . info ( ( ) => `Preparing schedule data for other days than currently selected one (${ otherDayIds . map ( id => id . value ) . join ( ", " ) } )` )
101126
@@ -114,9 +139,8 @@ export function useOfflineEventPreparation(
114139 schedulePreparationResolved ( ) ;
115140 } )
116141
117- promisesQueue . add ( async ( ) => {
118- await prepareSchedules ( user , confDescriptor , currentSchedule . day , extractTalksFromSchedule ( currentSchedule ) , otherDayIds , promisesQueue ) ;
119- } , { priority : 1000 } )
142+ await prepareEventInfos ( user , confDescriptor , promisesQueue )
143+ await prepareSchedules ( user , confDescriptor , currentSchedule . day , extractTalksFromSchedule ( currentSchedule ) , otherDayIds , promisesQueue ) ;
120144 } )
121145 } ) ;
122146
0 commit comments