Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code path for getting package metadata calls into CreateCacheFileAsync while running on the UI thread #4739

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,16 @@ private async ValueTask RefreshInstalledAndUpdatesTabsAsync()

private async Task<(int, int)> GetInstalledVulnerableAndDeprecatedPackagesCountAsync(PackageLoadContext loadContext, CancellationToken token)
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
nkolev92 marked this conversation as resolved.
Show resolved Hide resolved
IReadOnlyCollection<PackageSourceContextInfo> packageSources = SelectedSource.PackageSources;

// Switch off the UI thread before fetching installed packages and deprecation metadata.
await TaskScheduler.Default;

PackageCollection installedPackages = await loadContext.GetInstalledPackagesAsync();

var installedPackageMetadata = await Task.WhenAll(
installedPackages.Select(p => GetPackageMetadataAsync(p, token)));
installedPackages.Select(p => GetPackageMetadataAsync(p, packageSources, token)));

int vulnerablePackagesCount = 0;
int deprecatedPackagesCount = 0;
Expand All @@ -975,13 +978,12 @@ private async ValueTask RefreshInstalledAndUpdatesTabsAsync()
return (vulnerablePackagesCount, deprecatedPackagesCount);
}

private async Task<(PackageSearchMetadataContextInfo, PackageDeprecationMetadataContextInfo)> GetPackageMetadataAsync(PackageCollectionItem package, CancellationToken cancellationToken)
private async Task<(PackageSearchMetadataContextInfo, PackageDeprecationMetadataContextInfo)> GetPackageMetadataAsync(PackageCollectionItem package, IReadOnlyCollection<PackageSourceContextInfo> packageSources, CancellationToken cancellationToken)
{
using (INuGetSearchService searchService = await _serviceBroker.GetProxyAsync<INuGetSearchService>(NuGetServices.SearchService, cancellationToken: cancellationToken))
{
Assumes.NotNull(searchService);
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
return await searchService.GetPackageMetadataAsync(package, SelectedSource.PackageSources, true, cancellationToken);
return await searchService.GetPackageMetadataAsync(package, packageSources, true, cancellationToken);
}
}

Expand Down