Skip to content

Commit

Permalink
(#508) Fix repository optimizations for NuGet V3
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gep13 committed Mar 13, 2023
1 parent b6a7753 commit 647e600
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static IEnumerable<T> GetRepositoryResource<T>(IEnumerable<SourceReposito
var resource = repository.GetResource<T>();
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
{
Expand Down
5 changes: 4 additions & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ public static IPackageSearchMetadata find_package(
IEnumerable<ListResource> 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)
{
Expand Down

0 comments on commit 647e600

Please sign in to comment.