Optimize getSubjectFromPath to avoid concurrent stat calls
Co-authored-by: bdehamer <[email protected]>
This commit is contained in:
co-authored by
bdehamer
parent
f00e913aa0
commit
6cf5fbc523
+12
-8
@@ -94,14 +94,18 @@ const getSubjectFromPath = async (
|
|||||||
// Expand the globbed paths to a list of actual paths
|
// Expand the globbed paths to a list of actual paths
|
||||||
const paths = await glob.create(subjectPaths).then(async g => g.glob())
|
const paths = await glob.create(subjectPaths).then(async g => g.glob())
|
||||||
|
|
||||||
// Filter path list to just the files (not directories)
|
// Filter path list to just the files (not directories), enforcing the maximum
|
||||||
const stats = await Promise.all(paths.map(async p => fs.stat(p)))
|
const files: string[] = []
|
||||||
const files = paths.filter((_, i) => stats[i].isFile())
|
for (const p of paths) {
|
||||||
|
const stat = await fs.stat(p)
|
||||||
if (files.length > MAX_SUBJECT_COUNT) {
|
if (stat.isFile()) {
|
||||||
throw new Error(
|
files.push(p)
|
||||||
`Too many subjects specified (${files.length}). The maximum number of subjects is ${MAX_SUBJECT_COUNT}.`
|
if (files.length > MAX_SUBJECT_COUNT) {
|
||||||
)
|
throw new Error(
|
||||||
|
`Too many subjects specified (${files.length}). The maximum number of subjects is ${MAX_SUBJECT_COUNT}.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
|||||||
Reference in New Issue
Block a user