File tree Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Expand file tree Collapse file tree 2 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -61,8 +61,17 @@ sub index : Chained('root') PathPart('') Args(0) {
6161 = $c -> model(' API::Favorite' )-> by_user( $author -> {user } )-> recv ;
6262 $took += $faves_data -> {took } || 0;
6363
64- $faves = [ map { $_ -> {fields } } @{ $faves_data -> {hits }-> {hits } } ];
65- single_valued_arrayref_to_scalar($faves );
64+ my @all_fav = map { $_ -> {fields }-> {distribution } }
65+ @{ $faves_data -> {hits }-> {hits } };
66+ my $noLatest = $c -> model(' API::Release' )-> no_latest(@all_fav );
67+
68+ $faves = [
69+ map {
70+ my $distro = $_ -> {fields }-> {distribution };
71+ $noLatest -> {$distro } ? () : $_ -> {fields };
72+ } @{ $faves_data -> {hits }-> {hits } }
73+ ];
74+ $self -> single_valued_arrayref_to_scalar($faves );
6675 $faves = [ sort { $b -> {date } cmp $a -> {date } } @{$faves } ];
6776 }
6877
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ use namespace::autoclean;
44
55extends ' MetaCPAN::Web::Model::API' ;
66
7+ use List::Util qw( first) ;
8+ use List::MoreUtils qw( uniq) ;
9+
710=head1 NAME
811
912MetaCPAN::Web::Model::Release - Catalyst Model
@@ -441,6 +444,43 @@ sub topuploaders {
441444 );
442445}
443446
447+ sub no_latest {
448+ my ( $self , @distributions ) = @_ ;
449+
450+ # If there are no distributions return
451+ return {} unless (@distributions );
452+
453+ @distributions = uniq @distributions ;
454+ my $result = $self -> request(
455+ ' /release/_search' ,
456+ {
457+ size => scalar @distributions ,
458+ query => {
459+ filtered => {
460+ query => { match_all => {} },
461+ filter => {
462+ and => [
463+ { terms => { distribution => \@distributions } },
464+ { term => { status => ' latest' } }
465+ ]
466+ }
467+ }
468+ },
469+ fields => [qw( distribution status) ]
470+ }
471+ )-> recv ;
472+
473+ my @latest
474+ = map { $_ -> {fields }-> {distribution } } @{ $result -> {hits }-> {hits } };
475+
476+ my %no_latest = map {
477+ my $distro = $_ ;
478+ ( first { $_ eq $distro } @latest ) ? () : ( $distro , 1 );
479+ } @distributions ;
480+
481+ return \%no_latest ;
482+ }
483+
444484__PACKAGE__ -> meta-> make_immutable;
445485
4464861;
You can’t perform that action at this time.
0 commit comments