@@ -55,8 +55,64 @@ const keynoters = defineCollection({
5555 } ) ,
5656} ) ;
5757
58+ // Cache for fetched data to prevent duplicate network requests
59+ let cachedSpeakersData : any = null ;
60+ let cachedSessionsData : any = null ;
61+
62+ // Shared data fetching function
63+ async function getCollectionsData ( ) {
64+ // Only fetch if not already cached
65+ if ( ! cachedSpeakersData || ! cachedSessionsData ) {
66+ const [ speakersResponse , sessionsResponse ] = await Promise . all ( [
67+ fetch (
68+ "https://gist.github.com/egeakman/469f9abb23a787df16d8787f438dfdb6/raw/62d2b7e77c1b078a0e27578c72598a505f9fafbf/speakers.json"
69+ ) ,
70+ fetch (
71+ "https://gist.githubusercontent.com/egeakman/eddfb15f32ae805e8cfb4c5856ae304b/raw/466f8c20c17a9f6c5875f973acaec60e4e4d0fae/sessions.json"
72+ ) ,
73+ ] ) ;
74+
75+ cachedSpeakersData = await speakersResponse . json ( ) ;
76+ cachedSessionsData = await sessionsResponse . json ( ) ;
77+ }
78+
79+ // Create indexed versions for efficient lookups
80+ const speakersById = Object . entries ( cachedSpeakersData ) . reduce (
81+ ( acc , [ id , speaker ] : [ string , any ] ) => {
82+ acc [ id ] = { id, ...speaker } ;
83+ return acc ;
84+ } ,
85+ { } as Record < string , any >
86+ ) ;
87+
88+ const sessionsById = Object . entries ( cachedSessionsData ) . reduce (
89+ ( acc , [ id , session ] : [ string , any ] ) => {
90+ acc [ id ] = { id, ...session } ;
91+ return acc ;
92+ } ,
93+ { } as Record < string , any >
94+ ) ;
95+
96+ return {
97+ speakersData : cachedSpeakersData ,
98+ sessionsData : cachedSessionsData ,
99+ speakersById,
100+ sessionsById,
101+ } ;
102+ }
103+
58104const speakers = defineCollection ( {
59- loader : file ( "src/content/speakers/data.json" ) ,
105+ loader : async ( ) : Promise < any > => {
106+ const { speakersData, sessionsById } = await getCollectionsData ( ) ;
107+
108+ return Object . values ( speakersData ) . map ( ( speaker : any ) => ( {
109+ id : speaker . slug ,
110+ ...speaker ,
111+ submissions : ( speaker . submissions || [ ] )
112+ . filter ( ( sessionId : string ) => sessionId in sessionsById )
113+ . map ( ( sessionId : string ) => sessionsById [ sessionId ] . slug ) ,
114+ } ) ) ;
115+ } ,
60116 schema : z . object ( {
61117 code : z . string ( ) ,
62118 name : z . string ( ) ,
@@ -74,7 +130,17 @@ const speakers = defineCollection({
74130} ) ;
75131
76132const sessions = defineCollection ( {
77- loader : file ( "src/content/sessions/data.json" ) ,
133+ loader : async ( ) : Promise < any > => {
134+ const { sessionsData, speakersById } = await getCollectionsData ( ) ;
135+
136+ return Object . values ( sessionsData ) . map ( ( session : any ) => ( {
137+ id : session . slug ,
138+ ...session ,
139+ speakers : ( session . speakers || [ ] )
140+ . filter ( ( speakerId : string ) => speakerId in speakersById )
141+ . map ( ( speakerId : string ) => speakersById [ speakerId ] . slug ) ,
142+ } ) ) ;
143+ } ,
78144 schema : z . object ( {
79145 code : z . string ( ) ,
80146 title : z . string ( ) ,
0 commit comments