Skip to content

Commit d9ab8f3

Browse files
authored
In path utils, speed up version lookups (#16915)
1 parent 0fe0b45 commit d9ab8f3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/path-utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const allProducts = require('./all-products')
66
const allVersions = require('./all-versions')
77
const { getNewVersionedPath } = require('./old-versions-utils')
88

9+
const supportedVersions = new Set(Object.keys(allVersions))
10+
911
// construct appropriate versioned path for any given HREF
1012
function getVersionedPathWithoutLanguage (href, version) {
1113
// start clean without language code or trailing slash
@@ -24,7 +26,7 @@ function getVersionedPathWithoutLanguage (href, version) {
2426

2527
// if the version found is not a currently supported version...
2628
let productObjectFromPath
27-
if (!Object.keys(allVersions).includes(versionFromPath)) {
29+
if (!supportedVersions.has(versionFromPath)) {
2830
// first check if the first segment is instead a current product;
2931
// example: /admin/foo or /desktop/foo
3032
productObjectFromPath = allProducts[versionFromPath]

0 commit comments

Comments
 (0)