Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1662 from metacpan/pr/1609
No backpans
  • Loading branch information
mickeyn committed May 12, 2017
2 parents 6506874 + 2f022e4 commit 67c7b0d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/MetaCPAN/Web/Controller/Author.pm
Expand Up @@ -61,7 +61,17 @@ sub index : Chained('root') PathPart('') Args(0) {
= $c->model('API::Favorite')->by_user( $author->{user} )->recv;
$took += $faves_data->{took} || 0;

$faves = [ map { $_->{fields} } @{ $faves_data->{hits}->{hits} } ];
my @all_fav = map { $_->{fields}->{distribution} }
@{ $faves_data->{hits}->{hits} };
my $noLatest = $c->model('API::Release')->no_latest(@all_fav)->recv;
$took += $noLatest->{took} || 0;

$faves = [
map {
my $distro = $_->{fields}->{distribution};
$noLatest->{no_latest}->{$distro} ? () : $_->{fields};
} @{ $faves_data->{hits}->{hits} }
];
single_valued_arrayref_to_scalar($faves);
$faves = [ sort { $b->{date} cmp $a->{date} } @{$faves} ];
}
Expand Down
52 changes: 52 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -4,6 +4,9 @@ use namespace::autoclean;

extends 'MetaCPAN::Web::Model::API';

use List::Util qw(first);
use List::MoreUtils qw(uniq);

=head1 NAME
MetaCPAN::Web::Model::Release - Catalyst Model
Expand Down Expand Up @@ -441,6 +444,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;

0 comments on commit 67c7b0d

Please sign in to comment.