GetInstalledAndTransitivePackagesAsync transitive origins computation can be optional#4788
GetInstalledAndTransitivePackagesAsync transitive origins computation can be optional#4788dominoFire merged 17 commits intodevfrom
Conversation
b49888a to
25a4029
Compare
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/PackageReferenceProject.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Services/NuGetPackageSearchService.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Services/NuGetPackageSearchService.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Services/NuGetProjectManagerService.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/PackageReferenceProject.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/IPackageReferenceProject.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/IPackageReferenceProject.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/PackageReferenceProject.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Common/IProjectContextInfoExtensions.cs
Outdated
Show resolved
Hide resolved
| { | ||
| if (isSolution) | ||
| { | ||
| // We only need the installed packages? What about recommender |
There was a problem hiding this comment.
I believe Recommender is only for the project-level PMUI. Ask @birgithi to be sure.
There was a problem hiding this comment.
Correct. The recommender is only project level at this time. We've considered including solution level, but we can deal with that when we decide to include it.
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Services/NuGetPackageSearchService.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Services/NuGetPackageSearchService.cs
Outdated
Show resolved
Hide resolved
...t.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/CpsPackageReferenceProjectTests.cs
Outdated
Show resolved
Hide resolved
...t.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/CpsPackageReferenceProjectTests.cs
Outdated
Show resolved
Hide resolved
...t.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/CpsPackageReferenceProjectTests.cs
Outdated
Show resolved
Hide resolved
Comment wording Co-authored-by: Jean-Pierre Briedé <jebriede@microsoft.com>
| ValueTask<IInstalledAndTransitivePackages> GetInstalledAndTransitivePackagesAsync( | ||
| IReadOnlyCollection<string> projectIds, | ||
| CancellationToken cancellationToken); | ||
| /// <summary> |
There was a problem hiding this comment.
NIT: Add an empty line.
There was a problem hiding this comment.
I will address this in a follow-up issue. NuGet/Home#12098
nkolev92
left a comment
There was a problem hiding this comment.
One small comment. It's ok to have fewer APIs in code completely owned by us.
| /// <param name="includeTransitiveOrigins">Set it to <c>true</c> to get transitive origins in transitive packages list</param> | ||
| /// <param name="token">Cancellation token</param> | ||
| /// <returns>A <see cref="ProjectPackages"/>A struct with two lists: installed and transitive packages</returns> | ||
| public Task<ProjectPackages> GetInstalledAndTransitivePackagesAsync(bool includeTransitiveOrigins, CancellationToken token); |
There was a problem hiding this comment.
nit: Given that this isn't a client visible public API, we don't have to duplicate the API :) We can just have 1.
There was a problem hiding this comment.
I will address this in a follow-up issue. NuGet/Home#12098
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetInstalledAndTransitivePackagesAsync_TransitiveOriginsParamSetToFalse_ReturnsInstalledAndTransitivePackagesOnlyAsync() |
There was a problem hiding this comment.
What about _ReturnsPackagesWithoutTransitiveOriginsAsync as a suffix?
Its current phrasing indicates it's only returning installed and transitive packages, but that's all we can return, there are no other package types at this time. The transitive origins are a child of transitive packages, not a sibling, so this wording would make it clearer that the test is validating all packages are returned without any transitive origins. Thoughts?
There was a problem hiding this comment.
I will address this in a follow-up issue. NuGet/Home#12098
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetInstalledAndTransitivePackagesAsync_TransitiveOriginsParamSetToTrue_ReturnsTransitiveOriginsAsync() |
There was a problem hiding this comment.
For consistency and clarity, I recommend _ReturnsPackagesWithTransitiveOriginsAsync for the suffix here.
There was a problem hiding this comment.
I will address this in a follow-up issue. NuGet/Home#12098
| // Assert | ||
| Assert.NotEmpty(packages.InstalledPackages); | ||
| Assert.NotEmpty(packages.TransitivePackages); | ||
| Assert.All(packages.TransitivePackages, pkg => Assert.NotEmpty(pkg.TransitiveOrigins)); |
There was a problem hiding this comment.
Assert the collection of transitive origins contains what you expect rather than just checking for it being non-empty, unless this is already covered in another test. If it's in another test, can you link it here? Thanks!
There was a problem hiding this comment.
I will address this in a follow-up issue. NuGet/Home#12098
| // Setup | ||
| var projectName = "project1"; | ||
| string projectFullPath = Path.Combine(rootDir.SolutionRoot, projectName + ".csproj"); | ||
|
|
||
| // Project | ||
| var projectCache = new ProjectSystemCache(); | ||
| IVsProjectAdapter projectAdapter = Mock.Of<IVsProjectAdapter>(); | ||
| CpsPackageReferenceProject project = CreateCpsPackageReferenceProject(projectName, projectFullPath, projectCache); | ||
|
|
||
| ProjectNames projectNames = GetTestProjectNames(projectFullPath, projectName); | ||
| PackageSpec packageSpec = GetPackageSpec(projectName, projectFullPath, "[2.0.0, )"); | ||
|
|
||
| // Restore info | ||
| DependencyGraphSpec projectRestoreInfo = ProjectTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); | ||
| projectCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, new List<IAssetsLogMessage>()); | ||
| projectCache.AddProject(projectNames, projectAdapter, project).Should().BeTrue(); | ||
|
|
||
| // Package directories | ||
| var sources = new List<PackageSource>(); | ||
| var packagesDir = new DirectoryInfo(Path.Combine(rootDir.SolutionRoot, "globalPackages")); | ||
| var packageSource = new DirectoryInfo(rootDir.PackageSource); | ||
| packagesDir.Create(); | ||
| packageSource.Create(); | ||
| sources.Add(new PackageSource(packageSource.FullName)); | ||
|
|
||
| var logger = new TestLogger(); | ||
| var request = new TestRestoreRequest(packageSpec, sources, packagesDir.FullName, logger) | ||
| { | ||
| LockFilePath = Path.Combine(rootDir.SolutionRoot, "project.assets.json") | ||
| }; | ||
|
|
||
| await SimpleTestPackageUtility.CreateFullPackageAsync(packageSource.FullName, "packageB", "1.0.0"); | ||
| await SimpleTestPackageUtility.CreateFullPackageAsync( | ||
| packageSource.FullName, | ||
| "packageA", | ||
| "2.15.3", | ||
| new Packaging.Core.PackageDependency[] | ||
| { | ||
| new Packaging.Core.PackageDependency("packageB", VersionRange.Parse("1.0.0")) | ||
| }); | ||
|
|
||
| var command = new RestoreCommand(request); | ||
| RestoreResult result = await command.ExecuteAsync(); | ||
| await result.CommitAsync(logger, CancellationToken.None); |
There was a problem hiding this comment.
Without looking too closely, this setup code looks very similar to the setup in PrepareTestProjectAsync. Can we use that here instead or refactor so we can share most of it?
There was a problem hiding this comment.
I will address this in a follow-up issue. NuGet/Home#12098
Superseeded by last review
Bug
Fixes:
https://github.com/NuGet/Client.Engineering/issues/1808
https://github.com/NuGet/Client.Engineering/issues/1780
Regression? Yes.
Last working version: VS 17.2
Description
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation
Validation
Profiled PM UI first load with a project with 10 installed packages and a thousand (1118) transitive packages. I used PerfView and captured CPU samples.
Perfview Histograms below shows a smaller CPU time usage. The Makespan metric is the duration of first and last sample captured in PerfView. A smaller Makespan indicates it took less time to run gitpa API. However, some cases, we had a larger Makespan, but histograms indicate a lower CPU usage. Measurements are in miliseconds
Browse tab
____________00____0_____0_____0____________ooo___oo____o________Consolidade tab in Solution PM UI
____________00___0___o_oo_______________0o______o_oo____________Installed tab