-
Notifications
You must be signed in to change notification settings - Fork 905
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
(GH-431) Add Count to List Command API #430
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ namespace chocolatey.infrastructure.app.nuget | |
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using NuGet; | ||
using configuration; | ||
|
||
|
@@ -25,13 +26,47 @@ namespace chocolatey.infrastructure.app.nuget | |
public static class NugetList | ||
{ | ||
public static IEnumerable<IPackage> GetPackages(ChocolateyConfiguration configuration, ILogger nugetLogger) | ||
{ | ||
return execute_package_search(configuration, nugetLogger); | ||
} | ||
|
||
public static int GetCount(ChocolateyConfiguration configuration, ILogger nugetLogger) | ||
{ | ||
return execute_package_search(configuration, nugetLogger).Count(); | ||
} | ||
|
||
private static IQueryable<IPackage> execute_package_search(ChocolateyConfiguration configuration, ILogger nugetLogger) | ||
{ | ||
var packageRepository = NugetCommon.GetRemoteRepository(configuration, nugetLogger); | ||
|
||
// Whether or not the package is remote determines two things: | ||
// 1. Does the repository have a notion of "listed"? | ||
// 2. Does it support prerelease in a straight-forward way? | ||
// Choco previously dealt with this by taking the path of least resistance and manually filtering out and sort unwanted packages | ||
// This result in blocking operations that didn't let service based repositories, like OData, take care of heavy lifting on the server. | ||
bool isRemote; | ||
var aggregateRepo = packageRepository as AggregateRepository; | ||
if (aggregateRepo != null) | ||
{ | ||
isRemote = aggregateRepo.Repositories.All(repo => repo is IServiceBasedRepository); | ||
} | ||
else | ||
{ | ||
isRemote = packageRepository is IServiceBasedRepository; | ||
} | ||
|
||
IQueryable<IPackage> results = packageRepository.Search(configuration.Input, configuration.Prerelease); | ||
|
||
if (configuration.AllVersions) | ||
{ | ||
return results.Where(PackageExtensions.IsListed).OrderBy(p => p.Id); | ||
if (isRemote) | ||
{ | ||
return results.OrderBy(p => p.Id); | ||
} | ||
else | ||
{ | ||
return results.Where(PackageExtensions.IsListed).OrderBy(p => p.Id).AsQueryable(); | ||
} | ||
} | ||
|
||
if (configuration.Prerelease && packageRepository.SupportsPrereleasePackages) | ||
|
@@ -43,17 +78,25 @@ public static IEnumerable<IPackage> GetPackages(ChocolateyConfiguration configur | |
results = results.Where(p => p.IsLatestVersion); | ||
} | ||
|
||
if (!isRemote) | ||
{ | ||
results = | ||
results | ||
.Where(PackageExtensions.IsListed) | ||
.Where(p => configuration.Prerelease || p.IsReleaseVersion()) | ||
.distinct_last(PackageEqualityComparer.Id, PackageComparer.Version) | ||
.AsQueryable(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can live with this :) |
||
if (configuration.ListCommand.Page.HasValue) | ||
{ | ||
results = results.Skip(configuration.ListCommand.PageSize * configuration.ListCommand.Page.Value).Take(configuration.ListCommand.PageSize); | ||
} | ||
|
||
return results.OrderBy(p => p.Id) | ||
.AsEnumerable() | ||
.Where(PackageExtensions.IsListed) | ||
.Where(p => configuration.Prerelease || p.IsReleaseVersion()) | ||
.distinct_last(PackageEqualityComparer.Id, PackageComparer.Version); | ||
} | ||
return results.OrderBy(p => p.Id); | ||
} | ||
|
||
|
||
} | ||
|
||
// ReSharper restore InconsistentNaming | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the above checks were completely superfluous new as I can tell. The former was redundant with checks the server is already doing, and the later is redundant with the IsPrelease check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure you are testing against multiple NuGet source types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any other recommended NuGet sources I should test against besides Chocolatey?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier when @Jaykul was working on some of this that was similar I could not get the results to match. It wasn't necessarily the count, although it was off as well. It was the order coming back from the query, it was off. #224 (comment) and #224 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'd really love to see before someone starts changing these core bits is some integration tests that really test this out (prior to making the changes). Then make the changes and see if everything is still kosher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely agree. Something I was thinking about. Just have to figure out how to reliable intregration test this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing them, I'm going to run into the exact same issue, but I'm also unwilling to add distinct_last back. I'd much rather find a way to detect whether if the underlying provider is sourcing from a server than make Search a blocking operation.