Skip to content

Commit cb9b4b6

Browse files
authored
repo sync
2 parents ef3d3ad + d9ab8f3 commit cb9b4b6

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

lib/data-directory.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ const assert = require('assert')
22
const fs = require('fs').promises
33
const path = require('path')
44
const walk = require('walk-sync')
5+
const { mapLimit } = require('async')
56
const yaml = require('js-yaml')
67
const { isRegExp, set } = require('lodash')
78
const filenameToKey = require('./filename-to-key')
89

10+
const FILE_READ_LIMIT = 100
11+
912
module.exports = async function dataDirectory (dir, opts = {}) {
1013
const defaultOpts = {
1114
preprocess: (content) => { return content },
@@ -31,15 +34,18 @@ module.exports = async function dataDirectory (dir, opts = {}) {
3134
const data = {}
3235

3336
// find YAML and Markdown files in the given directory, recursively
34-
await Promise.all(walk(dir, { includeBasePath: true })
37+
const filenames = walk(dir, { includeBasePath: true })
3538
.filter(filename => {
3639
// ignore files that match any of ignorePatterns regexes
3740
if (opts.ignorePatterns.some(pattern => pattern.test(filename))) return false
3841

3942
// ignore files that don't have a whitelisted file extension
4043
return opts.extensions.includes(path.extname(filename).toLowerCase())
4144
})
42-
.map(async filename => {
45+
await mapLimit(
46+
filenames,
47+
FILE_READ_LIMIT,
48+
async filename => {
4349
// derive `foo.bar.baz` object key from `foo/bar/baz.yml` filename
4450
const key = filenameToKey(path.relative(dir, filename))
4551
const extension = path.extname(filename).toLowerCase()
@@ -62,7 +68,8 @@ module.exports = async function dataDirectory (dir, opts = {}) {
6268
set(data, key, fileContent)
6369
break
6470
}
65-
}))
71+
}
72+
)
6673

6774
return data
6875
}

lib/pages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const walk = require('walk-sync').entries
33
const Page = require('./page')
44
const languages = require('./languages')
55
const { mapLimit, filterLimit } = require('async')
6-
const FILE_READ_LIMIT = 500
6+
7+
const FILE_READ_LIMIT = 100
78

89
async function loadPageList () {
910
const pageList = []

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)