Skip to content

Commit

Permalink
#74: preloading speakers data
Browse files Browse the repository at this point in the history
  • Loading branch information
fcamblor committed Nov 8, 2024
1 parent 7cb859c commit 5301b65
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions mobile/src/state/useConferenceDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {CompletablePromiseQueue} from "@/models/utils";
import {prepareSchedules} from "@/state/useSchedule";
import {typesafeI18n} from "@/i18n/i18n-vue";
import {resolvedEventFirestorePath} from "../../../shared/utilities/event-utils";
import {prepareEventSpeakers} from "@/state/useEventSpeakers";

function getConferenceDescriptorDoc(spacedEventId: SpacedEventId|undefined) {
if(!spacedEventId || !spacedEventId.eventId || !spacedEventId.eventId.value) {
Expand Down Expand Up @@ -138,6 +139,7 @@ export function useOfflineEventPreparation(
schedulePreparationResolved();
})

await prepareEventSpeakers(user, confDescriptor, promisesQueue);
await prepareEventInfos(user, confDescriptor, promisesQueue)
await prepareSchedules(user, confDescriptor, currentSchedule.day, extractTalksFromSchedule(currentSchedule), otherDayIds, promisesQueue);

Expand Down
29 changes: 26 additions & 3 deletions mobile/src/state/useEventSpeakers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {computed, Ref, toValue} from "vue";
import {deferredVuefireUseCollection, deferredVuefireUseDocument} from "@/views/vue-utils";
import {VoxxrinConferenceDescriptor} from "@/models/VoxxrinConferenceDescriptor";
import {collection, CollectionReference, doc, DocumentReference} from "firebase/firestore";
import {VoxxrinConferenceDescriptor, VoxxrinLanguaceCode} from "@/models/VoxxrinConferenceDescriptor";
import {collection, CollectionReference, doc, DocumentReference, getDocs } from "firebase/firestore";
import {db} from "@/state/firebase";
import {resolvedEventFirestorePath} from "../../../shared/utilities/event-utils";
import {LineupSpeaker} from "../../../shared/event-lineup.firestore";
import {createVoxxrinSpeakerFromFirestore, SpeakerId, speakerMatchesSearchTerms} from "@/models/VoxxrinSpeaker";
import {match} from "ts-pattern";
import {sortBy} from "@/models/utils";
import {CompletablePromiseQueue, sortBy} from "@/models/utils";
import {User} from "firebase/auth";
import {checkCache} from "@/services/Cachings";
import {Temporal} from "temporal-polyfill";
import {PERF_LOGGER} from "@/services/Logger";
import {loadSpeakerUrl} from "@/state/useEventTalk";

export function useLineupSpeakers(eventDescriptorRef: Ref<VoxxrinConferenceDescriptor|undefined>, searchTermsRef: Ref<string|undefined>) {

Expand Down Expand Up @@ -86,3 +91,21 @@ export function eventLineupSpeakerDocument(eventDescriptor: VoxxrinConferenceDes
`${resolvedEventFirestorePath(eventDescriptor.id.value, eventDescriptor.spaceToken?.value)}/speakers/${speakerId.value}`
) as DocumentReference<LineupSpeaker>;
}

export async function prepareEventSpeakers(user: User, conferenceDescriptor: VoxxrinConferenceDescriptor, promisesQueue: CompletablePromiseQueue) {
promisesQueue.add(() => checkCache(`eventSpeakersPreparation(eventId=${conferenceDescriptor.id.value})`,
Temporal.Duration.from({ hours: 24 }), // No need to have frequent refreshes for list of speakers...
async () => {
PERF_LOGGER.debug(`eventTalkPreparation(eventId=${conferenceDescriptor.id.value})`)

const speakersColl = eventLineupSpeakersCollections(conferenceDescriptor)[0];
const speakers = await getDocs(speakersColl)

promisesQueue.addAll(speakers.docs.map(speaker => () => {
const speakerData = speaker.data()
if(speakerData.photoUrl) {
return loadSpeakerUrl(speakerData.photoUrl);
}
}), {priority: 100 });
}), { priority: 1000 });
}
6 changes: 3 additions & 3 deletions mobile/src/state/useEventTalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export async function prepareEventTalk(

promisesQueue.addAll(talk.speakers.map(speaker => () => {
if(speaker.photoUrl) {
return loadSpeakerUrl(talk, speaker.photoUrl);
return loadSpeakerUrl(speaker.photoUrl, `talkId=${talk.id.value}`);
}
}), {priority: queuePriority });
});
}

const IN_MEMORY_SPEAKER_URL_PRELOADINGS = new Set<string>();
async function loadSpeakerUrl(talk: VoxxrinTalk, speakerUrl: string) {
const LOGGER = Logger.named(`loadTalkSpeakerUrl(${talk.id.value}): ${speakerUrl}`);
export async function loadSpeakerUrl(speakerUrl: string, loadingContext?: string|undefined) {
const LOGGER = Logger.named(`loadSpeakerUrl(${speakerUrl})${loadingContext ? `(context: ${loadingContext})`:``}`);

return new Promise(async resolve => {
if(IN_MEMORY_SPEAKER_URL_PRELOADINGS.has(speakerUrl)) {
Expand Down

0 comments on commit 5301b65

Please sign in to comment.