diff --git a/lib/MetaCPAN/Web/Controller/Author.pm b/lib/MetaCPAN/Web/Controller/Author.pm index 84da0810ab..80190a4ad8 100644 --- a/lib/MetaCPAN/Web/Controller/Author.pm +++ b/lib/MetaCPAN/Web/Controller/Author.pm @@ -58,7 +58,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} } + ]; $self->single_valued_arrayref_to_scalar($faves); $faves = [ sort { $b->{date} cmp $a->{date} } @{$faves} ]; } diff --git a/lib/MetaCPAN/Web/Model/API/Release.pm b/lib/MetaCPAN/Web/Model/API/Release.pm index 8cccdc4624..440d7d4d39 100644 --- a/lib/MetaCPAN/Web/Model/API/Release.pm +++ b/lib/MetaCPAN/Web/Model/API/Release.pm @@ -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 @@ -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;