Skip to content

Commit 3d366eb

Browse files
author
Peter Bengtsson
authored
cache download of archived redirects.json (#23090)
Part of #1272
1 parent 57a9fd2 commit 3d366eb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

middleware/archived-enterprise-versions.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ const archivedFrontmatterFallbacks = readJsonFile(
1616
'./lib/redirects/static/archived-frontmatter-fallbacks.json'
1717
)
1818

19+
async function getRemoteJSON(url) {
20+
if (_getRemoteJSONCache.has(url)) {
21+
return _getRemoteJSONCache.get(url)
22+
}
23+
const body = await got(url).json()
24+
_getRemoteJSONCache.set(url, body)
25+
return body
26+
}
27+
const _getRemoteJSONCache = new Map()
28+
1929
// This module handles requests for deprecated GitHub Enterprise versions
2030
// by routing them to static content in help-docs-archived-enterprise-versions
2131

@@ -49,8 +59,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
4959

5060
if (versionSatisfiesRange(requestedVersion, `>${lastVersionWithoutArchivedRedirectsFile}`)) {
5161
try {
52-
const r = await got(getProxyPath('redirects.json', requestedVersion))
53-
const redirectJson = JSON.parse(r.body)
62+
const redirectJson = await getRemoteJSON(getProxyPath('redirects.json', requestedVersion))
5463

5564
// make redirects found via redirects.json redirect with a 301
5665
if (redirectJson[req.path]) {

0 commit comments

Comments
 (0)