Skip to content

Commit 0fe0b45

Browse files
heiskrchiedo
andauthored
Move data-directory to also mapLimit (#16921)
Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
1 parent 06364de commit 0fe0b45

2 files changed

Lines changed: 12 additions & 4 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 = []

0 commit comments

Comments
 (0)