Skip to content

Commit

Permalink
(GH-1770) Feature - usePackageRepositoryOptimizations
Browse files Browse the repository at this point in the history
Add a feature turned on by default named
`usePackageRepositoryOptimizations` that uses the new methods for
querying. Also allow turning off per install/upgrade command with
`--disable-repository-optimizations`. When turned off or disabled,
Chocolatey will query for available packages for
install/upgrade/outdated using the older methods. This allows
compatibility with repositories that error or do not support the
optimizations.
  • Loading branch information
ferventcoder committed Mar 22, 2019
1 parent 0668f3a commit 553eaa2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static class Features
public static readonly string LogWithoutColor = "logWithoutColor";
public static readonly string ExitOnRebootDetected = "exitOnRebootDetected";
public static readonly string LogValidationResultsOnWarnings = "logValidationResultsOnWarnings";
public static readonly string UsePackageRepositoryOptimizations = "usePackageRepositoryOptimizations";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.RemovePackageInformationOnUninstall = set_feature_flag(ApplicationParameters.Features.RemovePackageInformationOnUninstall, configFileSettings, defaultEnabled: false, description: "Remove Stored Package Information On Uninstall - When a package is uninstalled, should the stored package information also be removed? Available in 0.10.9+.");
config.Features.LogWithoutColor = set_feature_flag(ApplicationParameters.Features.LogWithoutColor, configFileSettings, defaultEnabled: false, description: "Log without color - Do not show colorization in logging output. Available in 0.10.9+.");
config.Features.LogValidationResultsOnWarnings = set_feature_flag(ApplicationParameters.Features.LogValidationResultsOnWarnings, configFileSettings, defaultEnabled: true, description: "Log validation results on warnings - Should the validation results be logged if there are warnings? Available in 0.10.12+.");
config.Features.UsePackageRepositoryOptimizations = set_feature_flag(ApplicationParameters.Features.UsePackageRepositoryOptimizations, configFileSettings, defaultEnabled: true, description: "Use Package Repository Optimizations - Turn on optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should generally be left enabled, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Available in 0.10.14+.");
config.Features.ScriptsCheckLastExitCode = set_feature_flag(ApplicationParameters.Features.ScriptsCheckLastExitCode, configFileSettings, defaultEnabled: false, description: "Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
configuration.Features.ExitOnRebootDetected = false;
}
})
.Add("disable-repository-optimizations|disable-package-repository-optimizations",
"Disable Package Repository Optimizations - Do not use optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should not generally be used, unless a repository needs to support older methods of query. When used, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.14+.".format_with
(ApplicationParameters.Features.UsePackageRepositoryOptimizations, configuration.Features.UsePackageRepositoryOptimizations.to_string()),
option =>
{
if (option != null)
{
configuration.Features.UsePackageRepositoryOptimizations = false;
}
})
;

//todo: package name can be a url / installertype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("ignore-unfound",
"Ignore Unfound Packages - Ignore packages that are not found on the sources used (or the defaults). Overrides the default feature '{0}' set to '{1}'. Available in 0.10.9+.".format_with(ApplicationParameters.Features.IgnoreUnfoundPackagesOnUpgradeOutdated, configuration.Features.IgnoreUnfoundPackagesOnUpgradeOutdated.to_string()),
option => configuration.Features.IgnoreUnfoundPackagesOnUpgradeOutdated = option != null)
.Add("disable-repository-optimizations|disable-package-repository-optimizations",
"Disable Package Repository Optimizations - Do not use optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should not generally be used, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.14+.".format_with
(ApplicationParameters.Features.UsePackageRepositoryOptimizations, configuration.Features.UsePackageRepositoryOptimizations.to_string()),
option =>
{
if (option != null)
{
configuration.Features.UsePackageRepositoryOptimizations = false;
}
})
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
configuration.Features.ExitOnRebootDetected = false;
}
})
.Add("disable-repository-optimizations|disable-package-repository-optimizations",
"Disable Package Repository Optimizations - Do not use optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should not generally be used, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.14+.".format_with
(ApplicationParameters.Features.UsePackageRepositoryOptimizations, configuration.Features.UsePackageRepositoryOptimizations.to_string()),
option =>
{
if (option != null)
{
configuration.Features.UsePackageRepositoryOptimizations = false;
}
})
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public sealed class FeaturesConfiguration
public bool RemovePackageInformationOnUninstall { get; set; }
public bool ExitOnRebootDetected { get; set; }
public bool LogValidationResultsOnWarnings { get; set; }
public bool UsePackageRepositoryOptimizations { get; set; }

//todo remove in 0.11.0
public bool ScriptsCheckLastExitCode { get; set; }
Expand Down
15 changes: 12 additions & 3 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ public virtual ConcurrentDictionary<string, PackageResult> install_run(Chocolate
continue;
}

IPackage availablePackage = find_package(packageName, version, config, packageManager.SourceRepository);
IPackage availablePackage = config.Features.UsePackageRepositoryOptimizations ?
find_package(packageName, version, config, packageManager.SourceRepository)
: packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);

if (availablePackage == null)
{
var logMessage = @"{0} not installed. The package was not found with the source(s) listed.
Expand Down Expand Up @@ -692,7 +695,10 @@ public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(Chocolate
config.Prerelease = true;
}

IPackage availablePackage = find_package(packageName, version, config, packageManager.SourceRepository);
IPackage availablePackage = config.Features.UsePackageRepositoryOptimizations ?
find_package(packageName, version, config, packageManager.SourceRepository)
: packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);

config.Prerelease = originalPrerelease;

if (availablePackage == null)
Expand Down Expand Up @@ -917,7 +923,10 @@ public virtual ConcurrentDictionary<string, PackageResult> get_outdated(Chocolat
config.Prerelease = true;
}

var latestPackage = find_package(packageName, null, config, repository);
SemanticVersion version = null;
var latestPackage = config.Features.UsePackageRepositoryOptimizations ?
find_package(packageName, null, config, packageManager.SourceRepository)
: packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);

if (latestPackage == null)
{
Expand Down

0 comments on commit 553eaa2

Please sign in to comment.