Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/MetaCPAN/Web/Controller/Author.pm
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;