11import type { Metadata } from 'next' ;
2+ import { cache } from 'react' ;
23import { Footer } from '@/components/footer' ;
34import Section from '@/components/landing/section' ;
45import { Spotlight } from '@/components/landing/spotlight' ;
@@ -125,59 +126,75 @@ function fetchWithRetry(
125126 return attemptFetch ( 1 ) ;
126127}
127128
128- async function fetchBasicRepoData ( requestInit : RequestInit ) {
129+ function fetchBasicRepoData ( requestInit : RequestInit ) : Promise < GitHubRepo > {
129130 // Fetch repository info
130- const repoResponse = await fetch (
131- 'https://api.github.com/repos/databuddy-analytics/Databuddy' ,
132- requestInit
133- ) ;
134- if ( ! repoResponse . ok ) {
135- throw new Error ( `Failed to fetch repo: ${ repoResponse . status } ` ) ;
136- }
137- return await repoResponse . json ( ) ;
131+ const cachedRepoResponse = cache ( async ( ) => {
132+ const repoResponse = await fetch (
133+ 'https://api.github.com/repos/databuddy-analytics/Databuddy' ,
134+ requestInit
135+ ) ;
136+ if ( ! repoResponse . ok ) {
137+ throw new Error ( `Failed to fetch repo: ${ repoResponse . status } ` ) ;
138+ }
139+ return await repoResponse . json ( ) ;
140+ } ) ;
141+ return cachedRepoResponse ( ) ;
138142}
139143
140- async function fetchContributorsData ( requestInit : RequestInit ) {
141- const contributorsResponse = await fetch (
142- 'https://api.github.com/repos/databuddy-analytics/Databuddy/contributors?per_page=100' ,
143- requestInit
144- ) ;
145- if ( ! contributorsResponse . ok ) {
146- throw new Error (
147- `Failed to fetch contributors: ${ contributorsResponse . status } `
144+ function fetchContributorsData (
145+ requestInit : RequestInit
146+ ) : Promise < GitHubContributor [ ] > {
147+ const cachedContributorsResponse = cache ( async ( ) => {
148+ const contributorsResponse = await fetch (
149+ 'https://api.github.com/repos/databuddy-analytics/Databuddy/contributors?per_page=100' ,
150+ requestInit
148151 ) ;
149- }
150- const contributorsData = await contributorsResponse . json ( ) ;
151- return Array . isArray ( contributorsData ) ? contributorsData : [ ] ;
152+ if ( ! contributorsResponse . ok ) {
153+ throw new Error (
154+ `Failed to fetch contributors: ${ contributorsResponse . status } `
155+ ) ;
156+ }
157+ return await contributorsResponse . json ( ) ;
158+ } ) ;
159+ return cachedContributorsResponse ( ) ;
152160}
153161
154- async function fetchLanguagesData ( requestInit : RequestInit ) {
155- const languagesResponse = await fetch (
156- 'https://api.github.com/repos/databuddy-analytics/Databuddy/languages' ,
157- requestInit
158- ) ;
159- if ( ! languagesResponse . ok ) {
160- throw new Error ( `Failed to fetch languages: ${ languagesResponse . status } ` ) ;
161- }
162- return await languagesResponse . json ( ) ;
162+ function fetchLanguagesData (
163+ requestInit : RequestInit
164+ ) : Promise < GitHubLanguages > {
165+ const cachedLanguagesResponse = cache ( async ( ) => {
166+ const languagesResponse = await fetch (
167+ 'https://api.github.com/repos/databuddy-analytics/Databuddy/languages' ,
168+ requestInit
169+ ) ;
170+ if ( ! languagesResponse . ok ) {
171+ throw new Error ( `Failed to fetch languages: ${ languagesResponse . status } ` ) ;
172+ }
173+ return await languagesResponse . json ( ) ;
174+ } ) ;
175+ return cachedLanguagesResponse ( ) ;
163176}
164177
165- async function fetchPullRequestsData ( requestInit : RequestInit ) {
166- const prsResponse = await fetch (
167- 'https://api.github.com/repos/databuddy-analytics/Databuddy/pulls?state=all&per_page=100' ,
168- requestInit
169- ) ;
170- if ( ! prsResponse . ok ) {
171- throw new Error ( `Failed to fetch PRs: ${ prsResponse . status } ` ) ;
172- }
173- const prsData = await prsResponse . json ( ) ;
174- return Array . isArray ( prsData ) ? prsData : [ ] ;
178+ function fetchPullRequestsData (
179+ requestInit : RequestInit
180+ ) : Promise < GitHubPullRequest [ ] > {
181+ const cachedPrsResponse = cache ( async ( ) => {
182+ const prsResponse = await fetch (
183+ 'https://api.github.com/repos/databuddy-analytics/Databuddy/pulls?state=all&per_page=100' ,
184+ requestInit
185+ ) ;
186+ if ( ! prsResponse . ok ) {
187+ throw new Error ( `Failed to fetch PRs: ${ prsResponse . status } ` ) ;
188+ }
189+ return await prsResponse . json ( ) ;
190+ } ) ;
191+ return cachedPrsResponse ( ) ;
175192}
176193
177- async function fetchCommitActivity (
194+ function fetchCommitActivity (
178195 statsRequestInit : RequestInit
179196) : Promise < ProcessedCommitActivity [ ] > {
180- try {
197+ const cachedCommitActivityResponse = cache ( async ( ) => {
181198 const response = await fetchWithRetry (
182199 'https://api.github.com/repos/databuddy-analytics/Databuddy/stats/commit_activity' ,
183200 statsRequestInit
@@ -211,17 +228,15 @@ async function fetchCommitActivity(
211228 `GitHub API returned ${ response . status } for commit activity`
212229 ) ;
213230 }
214- } catch ( error ) {
215- console . error ( 'Failed to fetch commit activity:' , error ) ;
216- }
217-
218- return statsCache . commitActivity || [ ] ;
231+ return [ ] ;
232+ } ) ;
233+ return cachedCommitActivityResponse ( ) ;
219234}
220235
221- async function fetchCodeFrequency (
236+ function fetchCodeFrequency (
222237 statsRequestInit : RequestInit
223238) : Promise < ProcessedCodeFrequency [ ] > {
224- try {
239+ const cachedCodeFrequencyResponse = cache ( async ( ) => {
225240 const response = await fetchWithRetry (
226241 'https://api.github.com/repos/databuddy-analytics/Databuddy/stats/code_frequency' ,
227242 statsRequestInit
@@ -247,17 +262,16 @@ async function fetchCodeFrequency(
247262 } else {
248263 console . warn ( `GitHub API returned ${ response . status } for code frequency` ) ;
249264 }
250- } catch ( error ) {
251- console . error ( 'Failed to fetch code frequency:' , error ) ;
252- }
265+ return [ ] ;
266+ } ) ;
253267
254- return statsCache . codeFrequency || [ ] ;
268+ return cachedCodeFrequencyResponse ( ) ;
255269}
256270
257- async function fetchPunchCard (
271+ function fetchPunchCard (
258272 statsRequestInit : RequestInit
259273) : Promise < ProcessedPunchCard [ ] > {
260- try {
274+ const cachedPunchCardResponse = cache ( async ( ) => {
261275 const response = await fetchWithRetry (
262276 'https://api.github.com/repos/databuddy-analytics/Databuddy/stats/punch_card' ,
263277 statsRequestInit
@@ -284,18 +298,13 @@ async function fetchPunchCard(
284298 } else {
285299 console . warn ( `GitHub API returned ${ response . status } for punch card` ) ;
286300 }
287- } catch ( error ) {
288- console . error ( 'Failed to fetch punch card:' , error ) ;
289- }
290-
291- // Return cached data if available, otherwise empty array
292- return statsCache . punchCard || [ ] ;
301+ return [ ] ;
302+ } ) ;
303+ return cachedPunchCardResponse ( ) ;
293304}
294305
295- async function fetchReleases (
296- requestInit : RequestInit
297- ) : Promise < ProcessedRelease [ ] > {
298- try {
306+ function fetchReleases ( requestInit : RequestInit ) : Promise < ProcessedRelease [ ] > {
307+ const cachedReleasesResponse = cache ( async ( ) => {
299308 const response = await fetch (
300309 'https://api.github.com/repos/databuddy-analytics/Databuddy/releases?per_page=20' ,
301310 requestInit
@@ -316,10 +325,9 @@ async function fetchReleases(
316325 . slice ( 0 , 10 ) ; // Latest 10 releases
317326 }
318327 }
319- } catch ( error ) {
320- console . error ( 'Failed to fetch releases:' , error ) ;
321- }
322- return [ ] ;
328+ return [ ] ;
329+ } ) ;
330+ return cachedReleasesResponse ( ) ;
323331}
324332
325333async function fetchGitHubData ( ) {
0 commit comments