Skip to content

Commit

Permalink
Multi-project gather cache
Browse files Browse the repository at this point in the history
  • Loading branch information
emgarten committed May 19, 2016
1 parent 50be40c commit e57cdd6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ public ResolutionContext ResolutionContext
{
get
{
_context = new ResolutionContext(GetDependencyBehavior(), _allowPrerelease, false, VersionConstraints.None);
// ResolutionContext contains a cache, this should only be created once per command
if (_context == null)
{
_context = new ResolutionContext(GetDependencyBehavior(), _allowPrerelease, false, VersionConstraints.None);
}

return _context;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public ResolutionContext ResolutionContext
{
get
{
_context = new ResolutionContext(GetDependencyBehavior(), _allowPrerelease, false, VersionConstraints.None);
// ResolutionContext contains a cache, this should only be created once per command
if (_context == null)
{
_context = new ResolutionContext(GetDependencyBehavior(), _allowPrerelease, false, VersionConstraints.None);
}

return _context;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ public ResolutionContext ResolutionContext
{
get
{
_context = new ResolutionContext(GetDependencyBehavior(), _allowPrerelease, false, DetermineVersionConstraints());
// ResolutionContext contains a cache, this should only be created once per command
if (_context == null)
{
_context = new ResolutionContext(GetDependencyBehavior(), _allowPrerelease, false, DetermineVersionConstraints());
}

return _context;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ private async Task<IReadOnlyList<ResolvedAction>> ResolveActionsForUpdate(
{
var resolvedActions = new List<ResolvedAction>();

// Keep a single gather cache across projects
var gatherCache = new GatherCache();

foreach (var project in uiService.Projects)
{
var installedPackages = await project.GetInstalledPackagesAsync(token);
Expand All @@ -150,7 +153,9 @@ private async Task<IReadOnlyList<ResolvedAction>> ResolveActionsForUpdate(
uiService.DependencyBehavior,
includePrelease: includePrerelease,
includeUnlisted: true,
versionConstraints: VersionConstraints.None);
versionConstraints: VersionConstraints.None,
gatherCache: gatherCache);

var actions = await _packageManager.PreviewUpdatePackagesAsync(
packagesToUpdateInProject,
project,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using NuGet.Resolver;

namespace NuGet.PackageManagement
Expand All @@ -14,12 +15,12 @@ public class ResolutionContext
/// Public constructor to create the resolution context
/// </summary>
public ResolutionContext()
: this(DependencyBehavior.Lowest,
includePrelease: false,
includeUnlisted: true,
versionConstraints: VersionConstraints.None,
gatherCache: new GatherCache())
{
DependencyBehavior = DependencyBehavior.Lowest;
IncludePrerelease = false;
IncludeUnlisted = true;
VersionConstraints = VersionConstraints.None;
GatherCache = new GatherCache();
}

/// <summary>
Expand All @@ -30,12 +31,34 @@ public ResolutionContext(
bool includePrelease,
bool includeUnlisted,
VersionConstraints versionConstraints)
: this(dependencyBehavior,
includePrelease,
includeUnlisted,
versionConstraints,
new GatherCache())
{
}

/// <summary>
/// Public constructor to create the resolution context
/// </summary>
public ResolutionContext(
DependencyBehavior dependencyBehavior,
bool includePrelease,
bool includeUnlisted,
VersionConstraints versionConstraints,
GatherCache gatherCache)
{
if (gatherCache == null)
{
throw new ArgumentNullException(nameof(gatherCache));
}

DependencyBehavior = dependencyBehavior;
IncludePrerelease = includePrelease;
IncludeUnlisted = includeUnlisted;
VersionConstraints = versionConstraints;
GatherCache = new GatherCache();
GatherCache = gatherCache;
}

/// <summary>
Expand All @@ -62,7 +85,6 @@ public ResolutionContext(
/// Gathe cache containing cached packages that can be used across operations.
/// Ex: Update-Package updates all packages across all projects, GatherCache stores
/// the gathered packages and re-uses them across all sub operations.
/// This property is for internal use or testing only.
/// </summary>
public GatherCache GatherCache { get; }
}
Expand Down
10 changes: 9 additions & 1 deletion src/NuGet.Core/NuGet.PackageManagement/NuGetPackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,15 @@ private async Task<IEnumerable<NuGetProjectAction>> PreviewUpdatePackagesForClas
{
// If any targets are prerelease we should gather with prerelease on and filter afterwards
var includePrereleaseInGather = resolutionContext.IncludePrerelease || (projectInstalledPackageReferences.Any(p => (p.PackageIdentity.HasVersion && p.PackageIdentity.Version.IsPrerelease)));
var contextForGather = new ResolutionContext(resolutionContext.DependencyBehavior, includePrereleaseInGather, resolutionContext.IncludeUnlisted, VersionConstraints.None);

// Create a modified resolution cache. This should include the same gather cache for multi-project
// operations.
var contextForGather = new ResolutionContext(
resolutionContext.DependencyBehavior,
includePrereleaseInGather,
resolutionContext.IncludeUnlisted,
VersionConstraints.None,
resolutionContext.GatherCache);

// Step-1 : Get metadata resources using gatherer
var projectName = NuGetProject.GetUniqueNameOrName(nuGetProject);
Expand Down

0 comments on commit e57cdd6

Please sign in to comment.