Skip to content

Commit 4deef52

Browse files
committed
Revert "fix(releases): add in-memory TTL cache for GitHub API responses"
This reverts commit 3d14b95.
1 parent 3d14b95 commit 4deef52

1 file changed

Lines changed: 41 additions & 80 deletions

File tree

src/releases/github.ts

Lines changed: 41 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,6 @@ export const SOCKET_BTM_REPO = {
103103

104104
const logger = getDefaultLogger()
105105

106-
// In-memory TTL cache for GitHub API responses.
107-
// Prevents redundant API calls during parallel asset downloads and
108-
// repeated builds (e.g., pre-commit hooks) within the same process.
109-
const API_CACHE_TTL_MS = 5 * 60_000
110-
const _apiCache = new Map<string, { data: unknown; expiresAt: number }>()
111-
112-
function getCachedApiResponse<T>(key: string): T | undefined {
113-
const entry = _apiCache.get(key)
114-
if (entry && entry.expiresAt > Date.now()) {
115-
return entry.data as T
116-
}
117-
if (entry) {
118-
_apiCache.delete(key)
119-
}
120-
return undefined
121-
}
122-
123-
function setCachedApiResponse(key: string, data: unknown): void {
124-
_apiCache.set(key, { data, expiresAt: Date.now() + API_CACHE_TTL_MS })
125-
}
126-
127106
let _fs: typeof import('node:fs') | undefined
128107
let _path: typeof import('node:path') | undefined
129108

@@ -383,42 +362,32 @@ export async function getLatestRelease(
383362
// Create matcher function if pattern provided.
384363
const isMatch = assetPattern ? createAssetMatcher(assetPattern) : undefined
385364

386-
const cacheKey = `releases:${owner}/${repo}`
387-
388365
return await pRetry(
389366
async () => {
390-
// Check in-memory cache first to avoid redundant API calls.
391-
let releases = getCachedApiResponse<
392-
Array<{
393-
tag_name: string
394-
published_at: string
395-
assets: Array<{ name: string }>
396-
}>
397-
>(cacheKey)
398-
399-
if (!releases) {
400-
// Fetch recent releases (100 should cover all tool releases).
401-
const response = await httpRequest(
402-
`https://api.github.com/repos/${owner}/${repo}/releases?per_page=100`,
403-
{
404-
headers: getAuthHeaders(),
405-
},
406-
)
407-
408-
if (!response.ok) {
409-
throw new Error(`Failed to fetch releases: ${response.status}`)
410-
}
367+
// Fetch recent releases (100 should cover all tool releases).
368+
const response = await httpRequest(
369+
`https://api.github.com/repos/${owner}/${repo}/releases?per_page=100`,
370+
{
371+
headers: getAuthHeaders(),
372+
},
373+
)
411374

412-
try {
413-
releases = JSON.parse(response.body.toString('utf8'))
414-
} catch (cause) {
415-
throw new Error(
416-
`Failed to parse GitHub releases response from https://api.github.com/repos/${owner}/${repo}/releases`,
417-
{ cause },
418-
)
419-
}
375+
if (!response.ok) {
376+
throw new Error(`Failed to fetch releases: ${response.status}`)
377+
}
420378

421-
setCachedApiResponse(cacheKey, releases)
379+
let releases: Array<{
380+
tag_name: string
381+
published_at: string
382+
assets: Array<{ name: string }>
383+
}>
384+
try {
385+
releases = JSON.parse(response.body.toString('utf8'))
386+
} catch (cause) {
387+
throw new Error(
388+
`Failed to parse GitHub releases response from https://api.github.com/repos/${owner}/${repo}/releases`,
389+
{ cause },
390+
)
422391
}
423392

424393
// Filter releases matching the tool prefix.
@@ -514,37 +483,29 @@ export async function getReleaseAssetUrl(
514483
? (input: string) => input === assetPattern
515484
: createAssetMatcher(assetPattern as AssetPattern)
516485

517-
const cacheKey = `release:${owner}/${repo}:${tag}`
518-
519486
return await pRetry(
520487
async () => {
521-
// Check in-memory cache first to avoid redundant API calls.
522-
let release = getCachedApiResponse<{
523-
assets: Array<{ name: string; browser_download_url: string }>
524-
}>(cacheKey)
525-
526-
if (!release) {
527-
const response = await httpRequest(
528-
`https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}`,
529-
{
530-
headers: getAuthHeaders(),
531-
},
532-
)
533-
534-
if (!response.ok) {
535-
throw new Error(`Failed to fetch release ${tag}: ${response.status}`)
536-
}
488+
const response = await httpRequest(
489+
`https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}`,
490+
{
491+
headers: getAuthHeaders(),
492+
},
493+
)
537494

538-
try {
539-
release = JSON.parse(response.body.toString('utf8'))
540-
} catch (cause) {
541-
throw new Error(
542-
`Failed to parse GitHub release response for tag ${tag}`,
543-
{ cause },
544-
)
545-
}
495+
if (!response.ok) {
496+
throw new Error(`Failed to fetch release ${tag}: ${response.status}`)
497+
}
546498

547-
setCachedApiResponse(cacheKey, release)
499+
let release: {
500+
assets: Array<{ name: string; browser_download_url: string }>
501+
}
502+
try {
503+
release = JSON.parse(response.body.toString('utf8'))
504+
} catch (cause) {
505+
throw new Error(
506+
`Failed to parse GitHub release response for tag ${tag}`,
507+
{ cause },
508+
)
548509
}
549510

550511
// Find the matching asset.

0 commit comments

Comments
 (0)