Skip to content

Commit

Permalink
Merge pull request #3195 from gep13/performance-fix
Browse files Browse the repository at this point in the history
(#3183 #3125) Fix performance issues with outbound HTTP queries
  • Loading branch information
AdmiringWorm authored Jun 5, 2023
2 parents e0939de + 8ad98ee commit e3e2ba8
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Chocolatey.NuGet.Common">
<HintPath>..\packages\Chocolatey.NuGet.Common.3.1.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Common.3.2.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Configuration">
<HintPath>..\packages\Chocolatey.NuGet.Configuration.3.1.0\lib\net472\Chocolatey.NuGet.Configuration.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Configuration.3.2.0\lib\net472\Chocolatey.NuGet.Configuration.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Frameworks">
<HintPath>..\packages\Chocolatey.NuGet.Frameworks.3.1.0\lib\net472\Chocolatey.NuGet.Frameworks.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Frameworks.3.2.0\lib\net472\Chocolatey.NuGet.Frameworks.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Packaging">
<HintPath>..\packages\Chocolatey.NuGet.Packaging.3.1.0\lib\net472\Chocolatey.NuGet.Packaging.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Packaging.3.2.0\lib\net472\Chocolatey.NuGet.Packaging.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Protocol">
<HintPath>..\packages\Chocolatey.NuGet.Protocol.3.1.0\lib\net472\Chocolatey.NuGet.Protocol.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Protocol.3.2.0\lib\net472\Chocolatey.NuGet.Protocol.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Versioning">
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.1.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.2.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
Expand Down
12 changes: 6 additions & 6 deletions src/chocolatey.tests.integration/packages.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Chocolatey.NuGet.Common" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Configuration" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Frameworks" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Packaging" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Protocol" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Versioning" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Common" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Configuration" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Frameworks" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Packaging" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Protocol" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Versioning" version="3.2.0" targetFramework="net48" />
<package id="log4net" version="2.0.12" targetFramework="net48" />
<package id="Microsoft.Web.Xdt" version="3.1.0" targetFramework="net48" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net40" />
Expand Down
26 changes: 13 additions & 13 deletions src/chocolatey.tests/chocolatey.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,43 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Chocolatey.NuGet.Commands">
<HintPath>..\packages\Chocolatey.NuGet.Commands.3.1.0\lib\net472\Chocolatey.NuGet.Commands.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Commands.3.2.0\lib\net472\Chocolatey.NuGet.Commands.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Common">
<HintPath>..\packages\Chocolatey.NuGet.Common.3.1.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Common.3.2.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Configuration">
<HintPath>..\packages\Chocolatey.NuGet.Configuration.3.1.0\lib\net472\Chocolatey.NuGet.Configuration.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Configuration.3.2.0\lib\net472\Chocolatey.NuGet.Configuration.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Credentials">
<HintPath>..\packages\Chocolatey.NuGet.Credentials.3.1.0\lib\net472\Chocolatey.NuGet.Credentials.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Credentials.3.2.0\lib\net472\Chocolatey.NuGet.Credentials.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.DependencyResolver.Core">
<HintPath>..\packages\Chocolatey.NuGet.DependencyResolver.Core.3.1.0\lib\net472\Chocolatey.NuGet.DependencyResolver.Core.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.DependencyResolver.Core.3.2.0\lib\net472\Chocolatey.NuGet.DependencyResolver.Core.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Frameworks">
<HintPath>..\packages\Chocolatey.NuGet.Frameworks.3.1.0\lib\net472\Chocolatey.NuGet.Frameworks.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Frameworks.3.2.0\lib\net472\Chocolatey.NuGet.Frameworks.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.LibraryModel">
<HintPath>..\packages\Chocolatey.NuGet.LibraryModel.3.1.0\lib\net472\Chocolatey.NuGet.LibraryModel.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.LibraryModel.3.2.0\lib\net472\Chocolatey.NuGet.LibraryModel.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.PackageManagement">
<HintPath>..\packages\Chocolatey.NuGet.PackageManagement.3.1.0\lib\net472\Chocolatey.NuGet.PackageManagement.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.PackageManagement.3.2.0\lib\net472\Chocolatey.NuGet.PackageManagement.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Packaging">
<HintPath>..\packages\Chocolatey.NuGet.Packaging.3.1.0\lib\net472\Chocolatey.NuGet.Packaging.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Packaging.3.2.0\lib\net472\Chocolatey.NuGet.Packaging.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.ProjectModel">
<HintPath>..\packages\Chocolatey.NuGet.ProjectModel.3.1.0\lib\net472\Chocolatey.NuGet.ProjectModel.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.ProjectModel.3.2.0\lib\net472\Chocolatey.NuGet.ProjectModel.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Protocol">
<HintPath>..\packages\Chocolatey.NuGet.Protocol.3.1.0\lib\net472\Chocolatey.NuGet.Protocol.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Protocol.3.2.0\lib\net472\Chocolatey.NuGet.Protocol.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Resolver">
<HintPath>..\packages\Chocolatey.NuGet.Resolver.3.1.0\lib\net472\Chocolatey.NuGet.Resolver.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Resolver.3.2.0\lib\net472\Chocolatey.NuGet.Resolver.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Versioning">
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.1.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.2.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
Expand Down
26 changes: 13 additions & 13 deletions src/chocolatey.tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Chocolatey.NuGet.Commands" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Common" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Configuration" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Credentials" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.DependencyResolver.Core" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Frameworks" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.LibraryModel" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.PackageManagement" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Packaging" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.ProjectModel" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Protocol" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Resolver" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Versioning" version="3.1.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Commands" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Common" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Configuration" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Credentials" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.DependencyResolver.Core" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Frameworks" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.LibraryModel" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.PackageManagement" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Packaging" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.ProjectModel" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Protocol" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Resolver" version="3.2.0" targetFramework="net48" />
<package id="Chocolatey.NuGet.Versioning" version="3.2.0" targetFramework="net48" />
<package id="log4net" version="2.0.12" targetFramework="net48" />
<package id="Microsoft.CSharp" version="4.3.0" targetFramework="net48" />
<package id="Microsoft.Web.Xdt" version="3.1.0" targetFramework="net48" />
Expand Down
26 changes: 13 additions & 13 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,43 +102,43 @@
<HintPath>..\packages\AlphaFS.2.1.3\lib\net40\AlphaFS.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Commands">
<HintPath>..\packages\Chocolatey.NuGet.Commands.3.1.0\lib\net472\Chocolatey.NuGet.Commands.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Commands.3.2.0\lib\net472\Chocolatey.NuGet.Commands.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Common">
<HintPath>..\packages\Chocolatey.NuGet.Common.3.1.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Common.3.2.0\lib\net472\Chocolatey.NuGet.Common.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Configuration">
<HintPath>..\packages\Chocolatey.NuGet.Configuration.3.1.0\lib\net472\Chocolatey.NuGet.Configuration.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Configuration.3.2.0\lib\net472\Chocolatey.NuGet.Configuration.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Credentials">
<HintPath>..\packages\Chocolatey.NuGet.Credentials.3.1.0\lib\net472\Chocolatey.NuGet.Credentials.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Credentials.3.2.0\lib\net472\Chocolatey.NuGet.Credentials.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.DependencyResolver.Core">
<HintPath>..\packages\Chocolatey.NuGet.DependencyResolver.Core.3.1.0\lib\net472\Chocolatey.NuGet.DependencyResolver.Core.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.DependencyResolver.Core.3.2.0\lib\net472\Chocolatey.NuGet.DependencyResolver.Core.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Frameworks">
<HintPath>..\packages\Chocolatey.NuGet.Frameworks.3.1.0\lib\net472\Chocolatey.NuGet.Frameworks.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Frameworks.3.2.0\lib\net472\Chocolatey.NuGet.Frameworks.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.LibraryModel">
<HintPath>..\packages\Chocolatey.NuGet.LibraryModel.3.1.0\lib\net472\Chocolatey.NuGet.LibraryModel.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.LibraryModel.3.2.0\lib\net472\Chocolatey.NuGet.LibraryModel.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.PackageManagement">
<HintPath>..\packages\Chocolatey.NuGet.PackageManagement.3.1.0\lib\net472\Chocolatey.NuGet.PackageManagement.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.PackageManagement.3.2.0\lib\net472\Chocolatey.NuGet.PackageManagement.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Packaging">
<HintPath>..\packages\Chocolatey.NuGet.Packaging.3.1.0\lib\net472\Chocolatey.NuGet.Packaging.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Packaging.3.2.0\lib\net472\Chocolatey.NuGet.Packaging.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.ProjectModel">
<HintPath>..\packages\Chocolatey.NuGet.ProjectModel.3.1.0\lib\net472\Chocolatey.NuGet.ProjectModel.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.ProjectModel.3.2.0\lib\net472\Chocolatey.NuGet.ProjectModel.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Protocol">
<HintPath>..\packages\Chocolatey.NuGet.Protocol.3.1.0\lib\net472\Chocolatey.NuGet.Protocol.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Protocol.3.2.0\lib\net472\Chocolatey.NuGet.Protocol.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Resolver">
<HintPath>..\packages\Chocolatey.NuGet.Resolver.3.1.0\lib\net472\Chocolatey.NuGet.Resolver.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Resolver.3.2.0\lib\net472\Chocolatey.NuGet.Resolver.dll</HintPath>
</Reference>
<Reference Include="Chocolatey.NuGet.Versioning">
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.1.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.2.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
Expand Down
22 changes: 18 additions & 4 deletions src/chocolatey/infrastructure.app/nuget/NuGetEndpointResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class NuGetEndpointResources
private static readonly ConcurrentDictionary<SourceRepository, NuGetEndpointResources> _cachedResources = new ConcurrentDictionary<SourceRepository, NuGetEndpointResources>();

private bool _resolvingFailed;
private readonly ChocolateySourceCacheContext _cacheContext;
private readonly Lazy<DependencyInfoResource> _dependencyInfoResource;
private readonly Lazy<DownloadResource> _downloadResource;
private readonly Lazy<FindPackageByIdResource> _findPackageResource;
Expand All @@ -34,10 +35,11 @@ public sealed class NuGetEndpointResources
private readonly Lazy<PackageUpdateResource> _packageUpdateResource;
private readonly Lazy<PackageSearchResource> _searchResource;

private NuGetEndpointResources(SourceRepository _sourceRepository)
private NuGetEndpointResources(SourceRepository _sourceRepository, ChocolateySourceCacheContext cacheContext)
{
Source = _sourceRepository;

_cacheContext = cacheContext;
_dependencyInfoResource = new Lazy<DependencyInfoResource>(() => ResolveResource<DependencyInfoResource>());
_downloadResource = new Lazy<DownloadResource>(() => ResolveResource<DownloadResource>());
_findPackageResource = new Lazy<FindPackageByIdResource>(() => ResolveResource<FindPackageByIdResource>());
Expand Down Expand Up @@ -105,21 +107,33 @@ public PackageSearchResource SearchResource

public SourceRepository Source { get; private set; }

[Obsolete("This overload is deprecated and will be removed in v3.")]
public static NuGetEndpointResources GetResourcesBySource(SourceRepository source)
{
return GetResourcesBySource(source, cacheContext: null);
}

public static NuGetEndpointResources GetResourcesBySource(SourceRepository source, ChocolateySourceCacheContext cacheContext)
{
return _cachedResources.GetOrAdd(source, (key) =>
{
var endpointResource = new NuGetEndpointResources(key);
var endpointResource = new NuGetEndpointResources(key, cacheContext);

return endpointResource;
});
}

[Obsolete("This overload is deprecated and will be removed in v3.")]
public static IEnumerable<NuGetEndpointResources> GetResourcesBySource(IEnumerable<SourceRepository> sources)
{
return GetResourcesBySource(sources, cacheContext: null);
}

public static IEnumerable<NuGetEndpointResources> GetResourcesBySource(IEnumerable<SourceRepository> sources, ChocolateySourceCacheContext cacheContext)
{
foreach (SourceRepository source in sources)
{
yield return GetResourcesBySource(source);
yield return GetResourcesBySource(source, cacheContext);
}
}

Expand All @@ -132,7 +146,7 @@ private T ResolveResource<T>()
{
this.Log().Debug("Resolving resource {0} for source {1}", typeof(T).Name, Source.PackageSource.Source);
#pragma warning disable RS0030 // Do not used banned APIs
resource = Source.GetResource<T>();
resource = Source.GetResource<T>(_cacheContext);
#pragma warning restore RS0030 // Do not used banned APIs
}
catch (AggregateException ex) when (!(ex.InnerException is null))
Expand Down
16 changes: 14 additions & 2 deletions src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,27 @@ public static IEnumerable<SourceRepository> GetRemoteRepositories(ChocolateyConf
return repositories;
}

[Obsolete("This overload is deprecated and will be removed in v3.")]
public static IReadOnlyList<NuGetEndpointResources> GetRepositoryResources(ChocolateyConfiguration configuration, ILogger nugetLogger, IFileSystem filesystem)
{
return GetRepositoryResources(configuration, nugetLogger, filesystem, new ChocolateySourceCacheContext(configuration));
}

public static IReadOnlyList<NuGetEndpointResources> GetRepositoryResources(ChocolateyConfiguration configuration, ILogger nugetLogger, IFileSystem filesystem, ChocolateySourceCacheContext cacheContext)
{
IEnumerable<SourceRepository> remoteRepositories = GetRemoteRepositories(configuration, nugetLogger, filesystem);
return GetRepositoryResources(remoteRepositories);
return GetRepositoryResources(remoteRepositories, cacheContext);
}

[Obsolete("This overload is deprecated and will be removed in v3.")]
public static IReadOnlyList<NuGetEndpointResources> GetRepositoryResources(IEnumerable<SourceRepository> packageRepositories)
{
return NuGetEndpointResources.GetResourcesBySource(packageRepositories).ToList();
return GetRepositoryResources(packageRepositories, cacheContext: null);
}

public static IReadOnlyList<NuGetEndpointResources> GetRepositoryResources(IEnumerable<SourceRepository> packageRepositories, ChocolateySourceCacheContext cacheContext)
{
return NuGetEndpointResources.GetResourcesBySource(packageRepositories, cacheContext).ToList();
}

public static void SetHttpHandlerCredentialService(ChocolateyConfiguration configuration)
Expand Down
Loading

0 comments on commit e3e2ba8

Please sign in to comment.