Skip to content

Commit

Permalink
Revert "Pass through the cache context to the vulnerability resource (#…
Browse files Browse the repository at this point in the history
…5361)"

This reverts commit 9ea2def.
  • Loading branch information
zivkan committed Aug 30, 2023
1 parent e4a9922 commit cdac490
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ public RestoreCommandProviders(
private static IReadOnlyList<IVulnerabilityInformationProvider> CreateVulnerabilityInfoProviders(IReadOnlyList<IRemoteDependencyProvider> remoteProviders)
{
List<IVulnerabilityInformationProvider> providers = new(remoteProviders.Count);
using var sourceCacheContext = new SourceCacheContext();
for (int i = 0; i < remoteProviders.Count; i++)
{
if (remoteProviders[i].SourceRepository != null)
{
providers.Add(new VulnerabilityInformationProvider(remoteProviders[i].SourceRepository, sourceCacheContext, NullLogger.Instance));
providers.Add(new VulnerabilityInformationProvider(remoteProviders[i].SourceRepository, NullLogger.Instance));
}
}
return providers;
Expand Down Expand Up @@ -151,7 +150,7 @@ public static RestoreCommandProviders Create(
var vulnerabilityInfoProviders = new List<IVulnerabilityInformationProvider>(remoteProviders.Count);
foreach (SourceRepository source in sources)
{
var provider = new VulnerabilityInformationProvider(source, cacheContext, log);
var provider = new VulnerabilityInformationProvider(source, log);
vulnerabilityInfoProviders.Add(provider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public RestoreCommandProviders GetOrCreate(
var vulnerabilityInformationProviders = new List<IVulnerabilityInformationProvider>(sources.Count);
foreach (SourceRepository source in sources)
{
IVulnerabilityInformationProvider provider = _vulnerabilityInformationProviders.GetOrAdd(source, s => new VulnerabilityInformationProvider(s, cacheContext, log));
IVulnerabilityInformationProvider provider = _vulnerabilityInformationProviders.GetOrAdd(source, s => new VulnerabilityInformationProvider(s, log));
vulnerabilityInformationProviders.Add(provider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ private PackageVulnerabilitySeverity ParseAuditLevel()

internal enum NuGetAuditMode { Unknown, Direct, All }

// Enum parsing and ToString are a magnitude of times slower than a naive implementation.
private NuGetAuditMode ParseAuditMode()
{
string? auditMode = _restoreAuditProperties?.AuditMode?.Trim();
Expand Down Expand Up @@ -432,7 +431,6 @@ internal enum EnabledValue
ExplicitOptOut
}

// Enum parsing and ToString are a magnitude of times slower than a naive implementation.
public static EnabledValue ParseEnableValue(string? value, string projectFullPath, ILogger logger)
{
if (string.IsNullOrEmpty(value) || string.Equals(value, "default", StringComparison.OrdinalIgnoreCase))
Expand All @@ -457,7 +455,6 @@ public static EnabledValue ParseEnableValue(string? value, string projectFullPat
return EnabledValue.Invalid;
}

// Enum parsing and ToString are a magnitude of times slower than a naive implementation.
internal static string GetString(EnabledValue enableAudit)
{
return enableAudit switch
Expand All @@ -470,7 +467,6 @@ internal static string GetString(EnabledValue enableAudit)
};
}

// Enum parsing and ToString are a magnitude of times slower than a naive implementation.
internal static string GetString(NuGetAuditMode auditMode)
{
return auditMode switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ namespace NuGet.Commands
internal sealed class VulnerabilityInformationProvider : IVulnerabilityInformationProvider
{
private readonly SourceRepository _source;
private readonly SourceCacheContext _sourceCacheContext;
private readonly ILogger _logger;

private readonly AsyncLazy<GetVulnerabilityInfoResult?> _vulnerabilityInfo;

public VulnerabilityInformationProvider(SourceRepository source, SourceCacheContext cacheContext, ILogger logger)
public VulnerabilityInformationProvider(SourceRepository source, ILogger logger)
{
_source = source;
_sourceCacheContext = cacheContext;
_logger = logger;

_vulnerabilityInfo = new AsyncLazy<GetVulnerabilityInfoResult?>(GetVulnerabilityInfoAsync);
Expand All @@ -44,7 +42,8 @@ public VulnerabilityInformationProvider(SourceRepository source, SourceCacheCont
return null;
}

GetVulnerabilityInfoResult result = await vulnerabilityInfoResource.GetVulnerabilityInfoAsync(_sourceCacheContext, _logger, CancellationToken.None);
using SourceCacheContext cacheContext = new();
GetVulnerabilityInfoResult result = await vulnerabilityInfoResource.GetVulnerabilityInfoAsync(cacheContext, _logger, CancellationToken.None);
return result;
}
}
Expand Down

0 comments on commit cdac490

Please sign in to comment.