File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,9 +110,20 @@ interface GitHubUserProfile {
110110 plan ?: { name ?: string } | null ;
111111}
112112
113- const contributionsCache = new TTLCache < ContributionCalendar > ( ) ;
114- const profileCache = new TTLCache < GitHubUserProfile > ( ) ;
115- const reposCache = new TTLCache < GitHubRepo [ ] > ( ) ;
113+ // Named constants to avoid magic numbers and allow future tuning
114+ const MAX_CONTRIBUTIONS_CACHE_SIZE = 1000 ;
115+ const MAX_PROFILE_CACHE_SIZE = 1000 ;
116+ const MAX_REPOS_CACHE_SIZE = 500 ;
117+
118+ // Bounded capacity controls to prevent unbounded heap memory leaks (OOM).
119+ // Under continuous crawler/bot scanning or viral peaks, unbounded cache size
120+ // allocations will exhaust Node/Vercel serverless RAM.
121+ // Specifying explicit capacity limits enforces a First-In, First-Out (FIFO)
122+ // eviction strategy (since standard ES6 Map maintains key insertion order) and
123+ // bounds max memory consumption to stable, predictable boundaries.
124+ const contributionsCache = new TTLCache < ContributionCalendar > ( MAX_CONTRIBUTIONS_CACHE_SIZE ) ;
125+ const profileCache = new TTLCache < GitHubUserProfile > ( MAX_PROFILE_CACHE_SIZE ) ;
126+ const reposCache = new TTLCache < GitHubRepo [ ] > ( MAX_REPOS_CACHE_SIZE ) ;
116127
117128function cacheKey (
118129 kind : 'contributions' | 'profile' | 'repos' ,
You can’t perform that action at this time.
0 commit comments