From 647e6001b94a2c02f9a4de27cce9700047a8fc24 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 13 Mar 2023 08:57:16 +0000 Subject: [PATCH] (#508) Fix repository optimizations for NuGet V3 When we re-introduced repository optimizations for Chocolatey, there was an assumption that there would always be a ListResource available for the feed. However, this has proven not to be the case. For example, when using something like Sleet or Baget, which are V3 only feeds, the ListResource does not exist. In these cases, we should defer to using the non-optimized queries.ThresholdHit This commit ensures that this is done, by only using the optimized query, when it is known that there is a ListResource available. --- src/chocolatey/infrastructure.app/nuget/NugetCommon.cs | 2 +- src/chocolatey/infrastructure.app/nuget/NugetList.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 63cf80dc0..1406554cc 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -238,7 +238,7 @@ public static IEnumerable GetRepositoryResource(IEnumerable(); if (resource is null) { - "chocolatey".Log().Warn("The source {0} failed to get a {1} resource".format_with(repository.PackageSource.Source, typeof(T))); + "chocolatey".Log().Warn(ChocolateyLoggers.LogFileOnly, "The source {0} failed to get a {1} resource".format_with(repository.PackageSource.Source, typeof(T))); } else { diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 5343561af..a68d0cf52 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -336,7 +336,10 @@ public static IPackageSearchMetadata find_package( IEnumerable listResources, NuGetVersion version = null) { - if (config.Features.UsePackageRepositoryOptimizations) + // We can only use the optimized ListResource query when the user has asked us to, via the UsePackageRepositoryOptimizations + // feature, as well as when a ListResource exists for the feed in question. Some technologies, such as Sleet or Baget, only + // offer V3 feeds, not V2, and as a result, no ListResource is available. + if (config.Features.UsePackageRepositoryOptimizations && listResources.Any()) { if (version is null) {