1
0
mirror of synced 2025-12-20 10:28:40 -05:00

In path utils, speed up version lookups (#16915)

This commit is contained in:
Kevin Heis
2020-12-14 08:07:44 -08:00
committed by GitHub
parent 0fe0b456e0
commit d9ab8f3b08

View File

@@ -6,6 +6,8 @@ const allProducts = require('./all-products')
const allVersions = require('./all-versions')
const { getNewVersionedPath } = require('./old-versions-utils')
const supportedVersions = new Set(Object.keys(allVersions))
// construct appropriate versioned path for any given HREF
function getVersionedPathWithoutLanguage (href, version) {
// start clean without language code or trailing slash
@@ -24,7 +26,7 @@ function getVersionedPathWithoutLanguage (href, version) {
// if the version found is not a currently supported version...
let productObjectFromPath
if (!Object.keys(allVersions).includes(versionFromPath)) {
if (!supportedVersions.has(versionFromPath)) {
// first check if the first segment is instead a current product;
// example: /admin/foo or /desktop/foo
productObjectFromPath = allProducts[versionFromPath]