1
0
mirror of synced 2025-12-23 11:54:18 -05:00

cache download of archived redirects.json (#23090)

Part of #1272
This commit is contained in:
Peter Bengtsson
2021-11-28 11:50:49 -05:00
committed by GitHub
parent 57a9fd298d
commit 3d366eb070

View File

@@ -16,6 +16,16 @@ const archivedFrontmatterFallbacks = readJsonFile(
'./lib/redirects/static/archived-frontmatter-fallbacks.json'
)
async function getRemoteJSON(url) {
if (_getRemoteJSONCache.has(url)) {
return _getRemoteJSONCache.get(url)
}
const body = await got(url).json()
_getRemoteJSONCache.set(url, body)
return body
}
const _getRemoteJSONCache = new Map()
// This module handles requests for deprecated GitHub Enterprise versions
// by routing them to static content in help-docs-archived-enterprise-versions
@@ -49,8 +59,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
if (versionSatisfiesRange(requestedVersion, `>${lastVersionWithoutArchivedRedirectsFile}`)) {
try {
const r = await got(getProxyPath('redirects.json', requestedVersion))
const redirectJson = JSON.parse(r.body)
const redirectJson = await getRemoteJSON(getProxyPath('redirects.json', requestedVersion))
// make redirects found via redirects.json redirect with a 301
if (redirectJson[req.path]) {