-
Notifications
You must be signed in to change notification settings - Fork 236
Nobackpans #1609
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
Closed
Closed
Nobackpans #1609
Changes from all commits
Commits
Show all changes
2 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -4,6 +4,9 @@ use namespace::autoclean; | |
|
||
extends 'MetaCPAN::Web::Model::API'; | ||
|
||
use List::Util qw(first); | ||
use List::MoreUtils qw(uniq); | ||
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 think we can change this to |
||
|
||
=head1 NAME | ||
|
||
MetaCPAN::Web::Model::Release - Catalyst Model | ||
|
@@ -440,6 +443,55 @@ sub topuploaders { | |
); | ||
} | ||
|
||
sub no_latest { | ||
my ( $self, @distributions ) = @_; | ||
my $cv = $self->cv; | ||
|
||
# If there are no distributions return | ||
return {} unless (@distributions); | ||
|
||
@distributions = uniq @distributions; | ||
$self->request( | ||
'/release/_search', | ||
{ | ||
size => scalar @distributions, | ||
query => { | ||
filtered => { | ||
query => { match_all => {} }, | ||
filter => { | ||
and => [ | ||
{ terms => { distribution => \@distributions } }, | ||
{ term => { status => 'latest' } } | ||
] | ||
} | ||
} | ||
}, | ||
fields => [qw(distribution status)] | ||
} | ||
)->cb( | ||
sub { | ||
my $data = shift->recv; | ||
my @latest | ||
= map { $_->{fields}->{distribution} } | ||
@{ $data->{hits}->{hits} }; | ||
$cv->send( | ||
{ | ||
took => $data->{took}, | ||
no_latest => { | ||
map { | ||
my $distro = $_; | ||
( first { $_ eq $distro } @latest ) | ||
? () | ||
: ( $distro, 1 ); | ||
} @distributions | ||
} | ||
} | ||
); | ||
} | ||
); | ||
return $cv; | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
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.
Could we call this variable
$no_latest
? We've been avoiding snake case in general.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.
I don't know if it matters or not but I tried to mimic ES data structures (seen that all the other methods returns an hash with some metadata and results are nested under the "hits" key) because I thought that metadata is still important (see the took key):
As bonus you can easily check if there are any hits at all by inspecting the no_latest hash's key number.
Maybe it could be renamed to "hits", so then you can access it with $noLatest->{hits}->{$distro} which is semantically better.
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.
I get why you did it -- it makes sense to me, but we don't really need to mimic the ES structure in this case (or worry about how long the query took). The purpose of the model is to take the ES data structures and massage them into something we can easily work with.
In this case the it's basically a question of whether or not a condition is true. So for that, the structure above is a lot more complex than we need.
It's a big codebase with a lot of code to follow, so my inclination is to merge only what we need moving forward. If we need more info at some point in the future, we can rework the model, but we're best off avoiding all increased complexity if we don't actually need it right now. In this case returning an array of dist names would be my preference. We can always use a map to create a hash if we need it. Or we can return the hash, but the extra keys aren't adding value just yet.