fix: make bfsFileSearch more efficient (#8173)

This commit is contained in:
Gaurav
2025-09-10 11:39:02 -07:00
committed by GitHub
parent ff705ec286
commit de2903b101

View File

@@ -99,6 +99,16 @@ export async function bfsFileSearch(
for (const { currentDir, entries } of results) {
for (const entry of entries) {
const fullPath = path.join(currentDir, entry.name);
const isDirectory = entry.isDirectory();
const isMatchingFile = entry.isFile() && entry.name === fileName;
if (!isDirectory && !isMatchingFile) {
continue;
}
if (isDirectory && ignoreDirsSet.has(entry.name)) {
continue;
}
if (
fileService?.shouldIgnoreFile(fullPath, {
respectGitIgnore: options.fileFilteringOptions?.respectGitIgnore,
@@ -109,11 +119,9 @@ export async function bfsFileSearch(
continue;
}
if (entry.isDirectory()) {
if (!ignoreDirsSet.has(entry.name)) {
queue.push(fullPath);
}
} else if (entry.isFile() && entry.name === fileName) {
if (isDirectory) {
queue.push(fullPath);
} else {
foundFiles.push(fullPath);
}
}