Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
Some old logic that was moved out of the templates before, but
doesn't seem to add any value.

The 'latest' value isn't used and the 'aggregated' doesn't
seem right - using existing 'releases' value do the job
just fine.
  • Loading branch information
mickeyn committed Jun 2, 2017
1 parent 1f94ec4 commit 91937cb
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 91937cb

Please sign in to comment.