@@ -268,6 +268,41 @@ interface GitHubUserProfile {
268268 plan ?: { name ?: string } | null ;
269269}
270270
271+ /**
272+ * Sanitizes a GitHub user profile to only include required fields.
273+ * This reduces the memory footprint of cached data.
274+ */
275+ function sanitizeUserProfile ( profile : GitHubUserProfile ) : GitHubUserProfile {
276+ return {
277+ login : profile . login ,
278+ name : profile . name ,
279+ avatar_url : profile . avatar_url ,
280+ public_repos : profile . public_repos ,
281+ followers : profile . followers ,
282+ following : profile . following ,
283+ created_at : profile . created_at ,
284+ bio : profile . bio ,
285+ location : profile . location ,
286+ type : profile . type ,
287+ plan : profile . plan ? { name : profile . plan . name } : null ,
288+ } ;
289+ }
290+
291+ /**
292+ * Sanitizes a GitHub repository object to only include required fields.
293+ * This reduces the memory footprint of cached data.
294+ */
295+ function sanitizeRepo ( repo : GitHubRepo ) : GitHubRepo {
296+ return {
297+ name : repo . name ,
298+ stargazers_count : repo . stargazers_count ,
299+ language : repo . language ,
300+ fork : repo . fork ,
301+ forks_count : repo . forks_count ,
302+ updated_at : repo . updated_at ,
303+ } ;
304+ }
305+
271306export function cacheKey (
272307 kind : 'contributions' | 'profile' | 'repos' | 'repos:contributed' ,
273308 username : string ,
@@ -580,8 +615,9 @@ async function fetchProfileUncached(
580615 }
581616
582617 const profile = ( await res . json ( ) ) as GitHubUserProfile ;
583- if ( ! options . bypassCache ) await profileCache . set ( key , profile , GITHUB_CACHE_TTL_MS ) ;
584- return profile ;
618+ const sanitizedProfile = sanitizeUserProfile ( profile ) ;
619+ if ( ! options . bypassCache ) await profileCache . set ( key , sanitizedProfile , GITHUB_CACHE_TTL_MS ) ;
620+ return sanitizedProfile ;
585621}
586622
587623export async function fetchUserRepos (
@@ -619,7 +655,7 @@ async function fetchReposUncached(
619655 }
620656
621657 const firstPageRepos = ( await firstPageRes . json ( ) ) as GitHubRepo [ ] ;
622- const allRepos : GitHubRepo [ ] = [ ... firstPageRepos ] ;
658+ const allRepos : GitHubRepo [ ] = firstPageRepos . map ( sanitizeRepo ) ;
623659
624660 const MAX_PAGES = 3 ;
625661
@@ -646,7 +682,8 @@ async function fetchReposUncached(
646682 throw new Error ( `GitHub REST API error: ${ response . status } ` ) ;
647683 }
648684
649- return ( await response . json ( ) ) as GitHubRepo [ ] ;
685+ const repos = ( await response . json ( ) ) as GitHubRepo [ ] ;
686+ return repos . map ( sanitizeRepo ) ;
650687 } )
651688 ) ;
652689
0 commit comments