-
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
Conversation
3042c74
to
47e2b5c
Compare
.Where(p => configuration.Prerelease || p.IsReleaseVersion()) | ||
.distinct_last(PackageEqualityComparer.Id, PackageComparer.Version) | ||
.Count(); | ||
} |
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.
This method could literally call return GetPackages(config, nugetLogger).Count();
. Thoughts?
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.
If they specified paging, then Count() would be inaccurate. The though process here is you could use the same config for both List
and Count
, and count would return the correct result.
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.
You could change the config momentarily. I'm more of a fan of that than I am duplicating code.
This needs a ticket filed on it. |
So, this is interesting. Two calls out then? :/ |
Only when paging is used, and when it is, Count will be called once while List will be called multiple times with given constraints. |
I also discovered that the way we handle filtering out unlisted packages is straight up wrong when dealing with paging and count. Looking into fixing that. |
Hrmm. Chocolatey's nuget is out of date, even for v2. They added and explicit switch on |
They also broke other things. That's why we are back on 2.8.2 |
Are you up to date with nuget-chocolatey too? It has the extensions I need to make this work efficiently. Failing that, I'm going to have to drop to a lower level and just build the query myself. |
Take a look at the 2.8.2_adds branch and submit fixes there |
Yup, just realized I was looking at the wrong branch. |
I was hoping that this wouldn't require a server change but it looks like NuGet's OData doesn't support datetime comparsions in it's IQueryable, and Chocolatey's server claims that IsListed doesn't exist. Server needs to either support an IsListed property or add isListed to it's search. |
nuget-chocolatey doesn't support searching against unlisted packages. Why was that check even there? |
So the isListed filter was completely superfluous unless I'm missing something. The results from the choco I just pushed return identical to the results from Choco v0.9.9. Count now returns in an average of 1-2 seconds, and using Page is ever so slightly faster too. |
|
||
public static int GetCount(ChocolateyConfiguration configuration, ILogger nugetLogger) | ||
{ | ||
return SearchPackagesImpl(configuration, nugetLogger).Count(); |
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.
If you're wondering why I put Count()
here, it's because I need IQueryable's Count. Otherwise it pulls down all the results, and gets the count of that.
We should add it.
I was not aware that nuget could support searching against unlisted packages. Does it allow it? |
Nope. That was me misunderstanding something. |
@ferventcoder developed a somewhat intelligent work around. Remote servers, aka OData chocolatey servers, seem to be very uniform and with my changes produce the same results. Other sources however behave....odd. So I now check if all the repositories we're searching against are remote. If they are, I let the server handle the heavy lifting. If not, we run the blocking filters that produce the correct results. The end result is |
// 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 previosly dealt with this by taking the path of least resistance and manually filtering out and sort unwanted packages |
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.
typo
Do you want to start squashing down/cleaning up your commits and adding the prepend |
Example of what I'm looking for with commit summary and message body - e15c3eb |
Yup! Wanted to get something we're happy with before cleaning up my commits :) |
8d06218
to
5433f8d
Compare
Squashed. |
5433f8d
to
ee2fe39
Compare
(and fixed type now that I think of it) |
I thought I saw at least two distinct commits in there. For squashing, I meant like the commit "Semicolon" and others |
ee2fe39
to
973bfcc
Compare
Hows that? |
Looks good! Now if there was some integration testing surrounding this, I wouldn't feel a need to manually test it. I'll pull it in for now and we can adjust if we need to later. :) |
@@ -222,6 +222,15 @@ public IEnumerable<T> List<T>() | |||
var runner = new GenericRunner(); | |||
return runner.list<T>(configuration, _container, isConsole: false, parseArgs: null); | |||
} | |||
|
|||
public int Count() |
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.
Actually, the name of this throws me. It's not clear what this method returns.
This method needs some xml documentation with it as well (looks like I missed calling that out in the list command PR).
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 about ListCount()?
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.
Hrmm. Normally I'd be against it, but I list ListCount works. Or rather GetListCount()
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.
Done.
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.
GetListCount sounds fine to. Count isn't clear on what it is doing, that's why I was hoping for more. It would be different if you were calling GetChocolatey().Setup().List().Count
6f503c9
to
b27f3b0
Compare
Commit cleanup? |
… makes sense. Updated Nuget List to attempt to use IQueryable all the way down for queries executed against service based repositories. This allows chocolatey to defer filtering, sorting, and paging to the server rather than the client. Reverts back to the old logic, though, for everything else.
Uses the IQueryable changes to add an efficient count for retrieving the number of results that would be returned by a list, usually in a much faster, more efficient way.
b27f3b0
to
981d1c5
Compare
Ohh, and we're all green again :D Edit: Darn't teamcity. |
(GH-431) Add Count to List Command API
Thanks! |
Adds the ability to efficiently retrieve a "count" for a given list command. Usefully for when you want to total number of given packages for a command that meets certain search criteria, but you're also using paging and need a reliable "total". Mostly only relevant to NuGet at this point.
Closes #431