Skip to content

Commit

Permalink
Merge pull request #1898 from metacpan/mickey/author_controller_cleanup
Browse files Browse the repository at this point in the history
Remove redundant code
  • Loading branch information
oalders committed Jun 2, 2017
2 parents 1f94ec4 + 91937cb commit b11b6fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
40 changes: 7 additions & 33 deletions lib/MetaCPAN/Web/Controller/Author.pm
Expand Up @@ -58,23 +58,20 @@ sub index : Chained('root') PathPart('') Args(0) {

my $releases = [ map { $_->{fields} } @{ $data->{hits}->{hits} } ];
single_valued_arrayref_to_scalar($releases);

my $date = List::Util::max
map { DateTime::Format::ISO8601->parse_datetime( $_->{date} ) }
@$releases;
$c->res->last_modified($date) if $date;

my ( $aggregated, $latest ) = @{ $self->_calc_aggregated($releases) };

$c->stash(
{
aggregated => $aggregated,
author => $author,
faves => $faves,
latest => $latest,
releases => $releases,
template => 'author.html',
took => $took,
total => $data->{hits}->{total},
author => $author,
faves => $faves,
releases => $releases,
template => 'author.html',
took => $took,
total => $data->{hits}->{total},
}
);

Expand Down Expand Up @@ -124,29 +121,6 @@ sub releases : Chained('root') PathPart Args(0) {
$c->stash( { pageset => $pageset } );
}

sub _calc_aggregated {
my ( $self, $releases ) = @_;

my @aggregated;
my $latest = $releases->[0];
my $last;

for my $rel ( @{$releases} ) {
my ( $canon_rel, $canon_lat ) = map {
DateTime::Format::ISO8601->parse_datetime($_)
->strftime("%Y%m%d%H%M%S")
} ( $rel->{date}, $latest->{date} );
$latest = $rel if $canon_rel > $canon_lat;

next if $last and $last eq $rel->{distribution};
$last = $rel->{distribution};
next unless $rel->{name};
push @aggregated, $rel;
}

return [ \@aggregated, $latest ];
}

__PACKAGE__->meta->make_immutable;

1;
2 changes: 1 addition & 1 deletion root/author.html
Expand Up @@ -139,7 +139,7 @@
</div>
<div class="visible-xs inline-author-pic"><% INCLUDE inc/author-pic.html author = author %></div>
<% IF releases.0 %>
<% INCLUDE inc/release-table.html releases = aggregated, header = 1, tablesorter = 1, table_id = "author_releases" %>
<% INCLUDE inc/release-table.html releases = releases, header = 1, tablesorter = 1, table_id = "author_releases" %>
<% ELSE %>
<div class="message">
<strong>Releases</strong>
Expand Down

0 comments on commit b11b6fe

Please sign in to comment.