Skip to content

Commit f149f7f

Browse files
authored
Merge pull request #12500 from github/repo-sync
repo sync
2 parents e990f33 + 6aee151 commit f149f7f

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

data/reusables/package_registry/checksum-maven-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{%- ifversion ghae %}
2-
1. In the `plugins` element of the *pom.xml* file, add the [checksum-maven-plugin](http://checksum-maven-plugin.nicoulaj.net/index.html) plugin, and configure the plugin to send at least SHA-256 checksums.
2+
1. In the `plugins` element of the *pom.xml* file, add the [checksum-maven-plugin](https://search.maven.org/artifact/net.nicoulaj.maven.plugins/checksum-maven-plugin) plugin, and configure the plugin to send at least SHA-256 checksums.
33
```xml
44
<plugins>
55
<plugin>

middleware/archived-enterprise-versions.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs'
12
import path from 'path'
23
import slash from 'slash'
34
import {
@@ -10,10 +11,24 @@ import isArchivedVersion from '../lib/is-archived-version.js'
1011
import got from 'got'
1112
import readJsonFile from '../lib/read-json-file.js'
1213
import { cacheControlFactory } from './cache-control.js'
13-
const archivedRedirects = readJsonFile(
14+
15+
function readJsonFileLazily(xpath) {
16+
const cache = new Map()
17+
// This will throw if the file isn't accessible at all, e.g. ENOENT
18+
fs.accessSync(xpath)
19+
return () => {
20+
if (!cache.has(xpath)) cache.set(xpath, readJsonFile(xpath))
21+
return cache.get(xpath)
22+
}
23+
}
24+
25+
// These files are huge so lazy-load them. But note that the
26+
// `readJsonFileLazily()` function will, at import-time, check that
27+
// the path does exist.
28+
const archivedRedirects = readJsonFileLazily(
1429
'./lib/redirects/static/archived-redirects-from-213-to-217.json'
1530
)
16-
const archivedFrontmatterFallbacks = readJsonFile(
31+
const archivedFrontmatterFallbacks = readJsonFileLazily(
1732
'./lib/redirects/static/archived-frontmatter-fallbacks.json'
1833
)
1934

@@ -55,7 +70,9 @@ export default async function archivedEnterpriseVersions(req, res, next) {
5570
versionSatisfiesRange(requestedVersion, `>=${firstVersionDeprecatedOnNewSite}`) &&
5671
versionSatisfiesRange(requestedVersion, `<=${lastVersionWithoutArchivedRedirectsFile}`)
5772
) {
58-
const redirect = archivedRedirects[req.path]
73+
// `archivedRedirects` is a callable because it's a lazy function
74+
// and memoized so calling it is cheap.
75+
const redirect = archivedRedirects()[req.path]
5976
if (redirect && redirect !== req.path) {
6077
cacheControl(res)
6178
return res.redirect(301, redirect)
@@ -122,7 +139,9 @@ function getFallbackRedirects(req, requestedVersion) {
122139
if (versionSatisfiesRange(requestedVersion, `<${firstVersionDeprecatedOnNewSite}`)) return
123140
if (versionSatisfiesRange(requestedVersion, `>${lastVersionWithoutArchivedRedirectsFile}`)) return
124141

125-
return archivedFrontmatterFallbacks.find((arrayOfFallbacks) =>
142+
// `archivedFrontmatterFallbacks` is a callable because it's a lazy function
143+
// and memoized so calling it is cheap.
144+
return archivedFrontmatterFallbacks().find((arrayOfFallbacks) =>
126145
arrayOfFallbacks.includes(req.path)
127146
)
128147
}

0 commit comments

Comments
 (0)