diff --git a/src/Shared/FileMatcher.cs b/src/Shared/FileMatcher.cs index 36e87bf5a35..c31de6d7c80 100644 --- a/src/Shared/FileMatcher.cs +++ b/src/Shared/FileMatcher.cs @@ -112,17 +112,46 @@ internal FileMatcher(IFileSystem fileSystem, GetFileSystemEntries getFileSystemE ? getFileSystemEntries : (type, path, pattern, directory, projectDirectory) => { - // Cache only directories, for files we won't hit the cache because the file name patterns tend to be unique - if (type == FileSystemEntity.Directories) + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave16_10)) { - return getFileSystemDirectoryEntriesCache.GetOrAdd( - $"{path};{pattern ?? "*"}", - s => getFileSystemEntries( - type, - path, - pattern, - directory, - projectDirectory).ToArray()); + // New behavior: + // Always hit the filesystem with "*" pattern, cache the results, and do the filtering here. + string cacheKey = type switch + { + FileSystemEntity.Files => "F", + FileSystemEntity.Directories => "D", + FileSystemEntity.FilesAndDirectories => "A", + _ => throw new NotImplementedException() + } + ";" + path; + IReadOnlyList allEntriesForPath = getFileSystemDirectoryEntriesCache.GetOrAdd( + cacheKey, + s => getFileSystemEntries( + type, + path, + "*", + directory, + projectDirectory).ToArray()); + if (pattern != null && pattern != "*") + { + return allEntriesForPath.Where(o => IsMatch(Path.GetFileName(o), pattern)); + } + return allEntriesForPath; + } + else + { + // Legacy behavior: + // Cache only directories, for files we won't hit the cache because the file name patterns tend to be unique + if (type == FileSystemEntity.Directories) + { + return getFileSystemDirectoryEntriesCache.GetOrAdd( + $"D;{path};{pattern ?? "*"}", + s => getFileSystemEntries( + type, + path, + pattern, + directory, + projectDirectory).ToArray()); + } } return getFileSystemEntries(type, path, pattern, directory, projectDirectory); };