From 6cf5fbc523e9b2d4be7fa28896f42bd31753bb93 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:00:46 +0000 Subject: [PATCH] Optimize getSubjectFromPath to avoid concurrent stat calls Co-authored-by: bdehamer <398027+bdehamer@users.noreply.github.com> --- src/subject.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/subject.ts b/src/subject.ts index 9bfdbbb..5bd5901 100644 --- a/src/subject.ts +++ b/src/subject.ts @@ -94,14 +94,18 @@ const getSubjectFromPath = async ( // Expand the globbed paths to a list of actual paths const paths = await glob.create(subjectPaths).then(async g => g.glob()) - // Filter path list to just the files (not directories) - const stats = await Promise.all(paths.map(async p => fs.stat(p))) - const files = paths.filter((_, i) => stats[i].isFile()) - - if (files.length > MAX_SUBJECT_COUNT) { - throw new Error( - `Too many subjects specified (${files.length}). The maximum number of subjects is ${MAX_SUBJECT_COUNT}.` - ) + // Filter path list to just the files (not directories), enforcing the maximum + const files: string[] = [] + for (const p of paths) { + const stat = await fs.stat(p) + if (stat.isFile()) { + files.push(p) + 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) {