Skip to content

Commit

Permalink
Cache all files and directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ladipro committed Feb 16, 2021
1 parent 94e3c19 commit 6aa2545
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/Shared/FileMatcher.cs
Expand Up @@ -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<string> 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);
};
Expand Down

0 comments on commit 6aa2545

Please sign in to comment.