Skip to content

Commit

Permalink
Added caching of loaded Directory.Packages.props files to avoid loadi…
Browse files Browse the repository at this point in the history
…ng the file for every NuGet package to check
  • Loading branch information
ThomasArdal committed Oct 25, 2024
1 parent a9f8128 commit 20280f7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/NuPU/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal class UpdateCommand : AsyncCommand<UpdateCommand.UpdateCommandSettings>
{
private const string UpToDate = " [green]up to date[/]";
private const string NeedsUpdate = " [red]needs update[/]";
private static readonly Dictionary<string, Dictionary<string, string>> cachedPackageVersions = [];

public override async Task<int> ExecuteAsync(CommandContext context, UpdateCommandSettings updateCommandSettings)
{
Expand Down Expand Up @@ -242,6 +243,12 @@ private static string GetPackageVersionFromProps(string packageId, DirectoryInfo

private static Dictionary<string, string> LoadPackageVersionsFromPropsFile(string directory)
{
// Check if this directory's package versions are already cached
if (cachedPackageVersions.TryGetValue(directory, out var cachedVersions))
{
return cachedVersions;
}

var packagesPropsPath = Path.Combine(directory, "Directory.Packages.props");
var packageVersions = new Dictionary<string, string>();

Expand All @@ -257,6 +264,9 @@ private static Dictionary<string, string> LoadPackageVersionsFromPropsFile(strin
packageVersions[packageName] = packageVersion;
}
}

// Cache the loaded package versions only if the file exists
cachedPackageVersions[directory] = packageVersions;
}

return packageVersions;
Expand Down

0 comments on commit 20280f7

Please sign in to comment.