From 779561738ca515343f01f4833fe96b86082dbce9 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Mon, 26 Jun 2023 19:09:51 -0500 Subject: [PATCH] (#3231) Don't refresh local package info during upgrade no-ops This optimizes the flow of the upgrade command. First, it uses the list of locally installed package from the if all is specified check, instead of throwing that away. Then, it will re-use the list for each package upgrade attempt, only refreshing the list when a package upgrade/install is attempted. This speeds up upgrade all runs, especially when a large (200+) number of packages are installed. --- .../infrastructure.app/services/NugetService.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 21f5df285..3d7598b7f 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -970,8 +970,9 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon var projectContext = new ChocolateyNuGetProjectContext(config, _nugetLogger); var configIgnoreDependencies = config.IgnoreDependencies; - SetPackageNamesIfAllSpecified(config, () => { config.IgnoreDependencies = true; }); + var allLocalPackages = SetPackageNamesIfAllSpecified(config, () => { config.IgnoreDependencies = true; }).ToList(); config.IgnoreDependencies = configIgnoreDependencies; + var localPackageListValid = true; config.CreateBackup(); @@ -981,7 +982,12 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon // before we start reading it. config.RevertChanges(); - var allLocalPackages = GetInstalledPackages(config).ToList(); + if (!localPackageListValid) + { + allLocalPackages = GetInstalledPackages(config).ToList(); + localPackageListValid = true; + } + var installedPackage = allLocalPackages.FirstOrDefault(p => p.Name.IsEqualTo(packageName)); var packagesToInstall = new List(); var packagesToUninstall = new HashSet(); @@ -1013,6 +1019,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon } string logMessage = @"{0} is not installed. Installing...".FormatWith(packageName); + localPackageListValid = false; if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, logMessage); @@ -1177,6 +1184,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon if (performAction) { + localPackageListValid = false; NugetCommon.GetPackageDependencies(availablePackage.Identity, NuGetFramework.AnyFramework, sourceCacheContext, _nugetLogger, remoteEndpoints, sourcePackageDependencyInfos, sourceDependencyCache, config).GetAwaiter().GetResult();