Skip to content

Commit

Permalink
remove mentions of "releases" as we are working with only one version…
Browse files Browse the repository at this point in the history
… of each dist.
  • Loading branch information
bricas committed Dec 13, 2013
1 parent 4660c25 commit 071241e
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 141 deletions.
2 changes: 1 addition & 1 deletion bin/authors.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
);

my $schema = CPAN::Changes::Web::schema( 'db' );
my @authors = $schema->resultset( 'Scan' )->first->releases( {}, { group_by => 'author', order_by => 'author' } )->get_column( 'author' )->all;
my @authors = $schema->resultset( 'Scan' )->latest->distributions( {}, { group_by => 'author', order_by => 'author' } )->get_column( 'author' )->all;
my $rs = $schema->resultset( 'Author' );
my $p = Parse::CPAN::Authors->new( "$minicpan/authors/01mailrc.txt.gz" );
my $counter = 0;
Expand Down
146 changes: 55 additions & 91 deletions lib/CPAN/Changes/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Text::Diff ();
our $VERSION = '0.1';

hook before => sub {
var scan => schema( 'db' )->resultset( 'Scan' )->search( { is_running => 0 } )->first;
var scan => schema( 'db' )->resultset( 'Scan' )->latest;
};

hook before_template => sub {
Expand All @@ -22,22 +22,20 @@ hook before_template => sub {
};

get '/' => sub {
my $releases = vars->{ scan }->releases;
my $pass = $releases->passes->count;
my $fail = $releases->failures->count;
my $dists = vars->{ scan }->distributions;
my $pass = $dists->passes->count;
my $fail = $dists->failures->count;

template 'index',
{
dist_uri => uri_for( '/dist' ),
dists =>
$releases->search( {}, { group_by => 'distribution' } )->count,
author_uri => uri_for( '/author' ),
authors => $releases->search( {}, { group_by => 'author' } )->count,
releases => $pass + $fail,
releases_pass => $pass,
releases_fail => $fail,
releases_progress => int( $pass / ( $pass + $fail ) * 100 ),
recent_releases => scalar $releases->recent,
dist_uri => uri_for( '/dist' ),
author_uri => uri_for( '/author' ),
authors => $dists->search( {}, { group_by => 'author' } )->count,
dists => $pass + $fail,
dists_pass => $pass,
dists_fail => $fail,
dists_progress => int( $pass / ( $pass + $fail ) * 100 ),
recent_releases => scalar $dists->recent,
};
};

Expand All @@ -53,35 +51,35 @@ get '/author' => sub {
author_uri => uri_for( '/author' ),
current_page => params->{ page },
entries_per_page => 1000,
authors => vars->{ scan }->releases->authors
authors => vars->{ scan }->distributions->authors
};
};

get '/author/:id' => sub {
my $releases = vars->{ scan }->releases( { author => params->{ id } } );
my $dists = vars->{ scan }->distributions( { author => params->{ id } } );

if ( !$releases->count ) {
if ( !$dists->count ) {
return send_error( 'Not Found', 404 );
}

my $pass = $releases->passes->count;
my $fail = $releases->failures->count;
my $pass = $dists->passes->count;
my $fail = $dists->failures->count;

my $author_info = $releases->authors->first;
my $author_info = $dists->authors->first;

var title => $author_info->name;

template 'author/id', {
dist_uri => uri_for( '/dist' ),
releases => $releases,
dists => $dists,
pass => $pass,
fail => $fail,
progress => int( $pass / ( $pass + $fail ) * 100 ),
author_info => $author_info,
header_links => [
{ rel => 'alternate',
type => 'application/atom+xml',
title => 'Releases by ' . params->{ id },
title => 'Distributions by ' . params->{ id },
href => uri_for( '/author/' . params->{ id } . '/feed' )
}
]
Expand All @@ -90,29 +88,29 @@ get '/author/:id' => sub {
};

get '/author/:id/feed' => sub {
my $releases = vars->{ scan }->releases( { author => params->{ id } },
my $dists = vars->{ scan }->distributions( { author => params->{ id } },
{ order_by => 'dist_timestamp DESC' } );
$releases = _handle_feed_filter( $releases );
$dists = _handle_feed_filter( $dists );

if ( !$releases->count ) {
if ( !$dists->count ) {
return send_error( 'Not Found', 404 );
}

my $author_info = $releases->authors->first;
my $author_info = $dists->authors->first;

my $feed = XML::Atom::SimpleFeed->new(
title => 'Releases by ' . $author_info->name,
title => 'Distributions by ' . $author_info->name,
link => uri_for( '/' ),
link => {
rel => 'self',
href => uri_for( '/author/' . params->{ id } . '/feed' ),
},
updated => $releases->first->dist_timestamp . 'Z',
updated => $dists->first->dist_timestamp . 'Z',
author => 'CPAN::Changes Kwalitee Service',
id => uri_for( '/author/' . params->{ id } . '/feed' ),
);

_releases_to_entries( $feed, $releases );
_releases_to_entries( $feed, $dists );

content_type( 'application/atom+xml' );
return $feed->as_string;
Expand All @@ -126,61 +124,15 @@ get '/dist' => sub {
current_page => params->{ page },
entries_per_page => 1000,
distributions => [
vars->{ scan }->releases( {}, { group_by => 'distribution' } )
vars->{ scan }->distributions( {}, { group_by => 'distribution' } )
->get_column( 'distribution' )->all
]
};
};

get '/dist/multiple-releases' => sub {
var title => 'Distributions with Multiple Releases';

template 'dist/index',
{
dist_uri => uri_for( '/dist' ),
current_page => params->{ page },
entries_per_page => 1000,
distributions => [
vars->{ scan }->releases( {}, { group_by => 'distribution', having => "count('distribution') > 1" } )
->get_column( 'distribution' )->all
]
};
};

get '/dist/:dist' => sub {
my $releases
= vars->{ scan }->releases( { distribution => params->{ dist } } );

if ( !$releases->count ) {
return send_error( 'Not Found', 404 );
}

my $pass = $releases->passes->count;
my $fail = $releases->failures->count;

var title => params->{ dist };

template 'dist/dist',
{
author_uri => uri_for( '/author' ),
dist_uri => uri_for( '/dist' ),
releases => $releases,
pass => $pass,
fail => $fail,
progress => int( $pass / ( $pass + $fail ) * 100 ),
header_links => [
{ rel => 'alternate',
type => 'application/atom+xml',
title => 'Releases for ' . params->{ dist },
href => uri_for( '/dist/' . params->{ dist } . '/feed' )
}
]
};
};

get '/dist/:dist/feed' => sub {
my $releases
= vars->{ scan }->releases( { distribution => params->{ dist } } );
= vars->{ scan }->distributions( { distribution => params->{ dist } } );
$releases = _handle_feed_filter( $releases );

if ( !$releases->count ) {
Expand Down Expand Up @@ -208,7 +160,7 @@ get '/dist/:dist/feed' => sub {

get '/dist/:dist/json' => sub {
my $release
= vars->{ scan }->releases( { distribution => params->{ dist } } )
= vars->{ scan }->distributions( { distribution => params->{ dist } } )
->first;

if ( !$release ) {
Expand All @@ -227,25 +179,37 @@ get '/dist/:dist/json' => sub {

};

get '/dist/:dist/:version' => sub {
my $release
= vars->{ scan }->releases(
{ distribution => params->{ dist }, version => params->{ version } } )
->first;
get '/dist/:dist' => \&_show_release;
get '/dist/:dist/:version?' => \&_show_release;

sub _show_release {
my %search = ( distribution => params->{ dist } );
if( params->{ version } ) {
$search{ version } = params->{ version };
}

my $release = vars->{ scan }->distributions( \%search )->first;

if ( !$release ) {
return send_error( 'Not Found', 404 );
}

var title => sprintf( '%s %s (%s)',
params->{ dist },
params->{ version },
$release->version,
$release->author );

my %tt = (
author_uri => uri_for( '/author' ),
dist_uri => uri_for( '/dist' ),
release => $release,
author_uri => uri_for( '/author' ),
dist_uri => uri_for( '/dist' ),
release => $release,
header_links => [
{ rel => 'alternate',
type => 'application/atom+xml',
title => 'Releases for ' . params->{ dist },
href => uri_for( '/dist/' . params->{ dist } . '/feed' )
}
]
);

unless ( $release->failure ) {
Expand Down Expand Up @@ -274,7 +238,7 @@ get '/search' => sub {
current_page => params->{ page },
dist_uri => uri_for( '/dist' ),
distributions => [
vars->{ scan }->releases(
vars->{ scan }->distributions(
{ distribution => { 'like', "%$search%" } },
{ group_by => 'distribution',
order_by => 'lower(distribution)'
Expand All @@ -290,7 +254,7 @@ get '/search' => sub {
entries_per_page => 250,
current_page => params->{ page },
author_uri => uri_for( '/author' ),
authors => vars->{ scan }->releases->authors->search_rs(
authors => vars->{ scan }->distributions->authors->search_rs(
{ -or => {
'author_info.id' => { 'like', "%$search%" },
'author_info.name' => { 'like', "%$search%" },
Expand All @@ -304,7 +268,7 @@ get '/search' => sub {
get '/hof' => sub {
var title => 'Hall of Fame';
my $scan = vars->{ scan };
my $total = $scan->releases->authors->count;
my $total = $scan->distributions->authors->count;
my $hof = $scan->hall_of_fame_authors;
my $pass = $hof->count;

Expand Down Expand Up @@ -372,7 +336,7 @@ post '/validate' => sub {
};

get '/recent/feed' => sub {
my $releases = vars->{ scan }->releases->recent;
my $releases = vars->{ scan }->distributions->recent;
$releases = _handle_feed_filter( $releases );

my $feed = XML::Atom::SimpleFeed->new(
Expand Down
2 changes: 1 addition & 1 deletion lib/CPAN/Changes/Web/Schema/Result/Author.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ __PACKAGE__->set_primary_key( 'id' );
__PACKAGE__->resultset_attributes( { order_by => [ 'id' ] } );

__PACKAGE__->has_many(
releases => 'CPAN::Changes::Web::Schema::Result::Release' => 'author' );
distributions => 'CPAN::Changes::Web::Schema::Result::Distribution' => 'author' );

1;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package CPAN::Changes::Web::Schema::Result::Release;
package CPAN::Changes::Web::Schema::Result::Distribution;

use strict;
use warnings;
Expand Down Expand Up @@ -78,10 +78,10 @@ __PACKAGE__->set_primary_key( 'id' );
__PACKAGE__->add_unique_constraint(
release_key => [ qw( distribution author version ) ], );

__PACKAGE__->has_many( scan_release_joins =>
'CPAN::Changes::Web::Schema::Result::ScanReleaseJoin' =>
__PACKAGE__->has_many( scan_distribution_joins =>
'CPAN::Changes::Web::Schema::Result::ScanDistributionJoin' =>
'release_id' );
__PACKAGE__->many_to_many( scans => 'scan_release_joins' => 'scan' );
__PACKAGE__->many_to_many( scans => 'scan_distribution_joins' => 'scan' );

__PACKAGE__->might_have(
'author_info' => 'CPAN::Changes::Web::Schema::Result::Author',
Expand Down
10 changes: 5 additions & 5 deletions lib/CPAN/Changes/Web/Schema/Result/Scan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key( 'id' );
__PACKAGE__->resultset_attributes( { order_by => [ 'run_date DESC' ] } );

__PACKAGE__->has_many( scan_release_joins =>
'CPAN::Changes::Web::Schema::Result::ScanReleaseJoin' => 'scan_id' );
__PACKAGE__->has_many( scan_distribution_joins =>
'CPAN::Changes::Web::Schema::Result::ScanDistributionJoin' => 'scan_id' );
__PACKAGE__->many_to_many(
releases => 'scan_release_joins' => 'distribution_release'
distributions => 'scan_distribution_joins' => 'distribution'
);

sub hall_of_fame_authors {
my $self = shift;
my $inner = $self->releases( { failure => { NOT => undef } } );
my $inner = $self->distributions( { failure => { NOT => undef } } );

return $self->releases(
return $self->distributions(
{ author => { 'NOT IN' => $inner->get_column( 'author' )->as_query }
}
)->authors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package CPAN::Changes::Web::Schema::Result::ScanReleaseJoin;
package CPAN::Changes::Web::Schema::Result::ScanDistributionJoin;

use strict;
use warnings;
Expand All @@ -25,7 +25,7 @@ __PACKAGE__->belongs_to(
'scan_id'
);
__PACKAGE__->belongs_to(
distribution_release => 'CPAN::Changes::Web::Schema::Result::Release',
distribution => 'CPAN::Changes::Web::Schema::Result::Distribution',
'release_id'
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package CPAN::Changes::Web::Schema::ResultSet::Release;
package CPAN::Changes::Web::Schema::ResultSet::Distribution;

use strict;
use warnings;
Expand All @@ -20,8 +20,8 @@ sub recent {
{ dist_timestamp => {
'>=',
# SQLite-ism
# \q((SELECT strftime('%Y-%m-%d', MAX( dist_timestamp )) FROM distribution_release))
\q((SELECT DATE_FORMAT(MAX(dist_timestamp), '%Y-%m-%d') FROM distribution_release))
\q((SELECT strftime('%Y-%m-%d', MAX( dist_timestamp )) FROM distribution_release))
# \q((SELECT DATE_FORMAT(MAX(dist_timestamp), '%Y-%m-%d') FROM distribution_release))
}
},
{ order_by => 'dist_timestamp DESC' }
Expand Down
12 changes: 12 additions & 0 deletions lib/CPAN/Changes/Web/Schema/ResultSet/Scan.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package CPAN::Changes::Web::Schema::ResultSet::Scan;

use strict;
use warnings;

use parent 'DBIx::Class::ResultSet';

sub latest {
return shift->search( { is_running => 0 }, { order_by => 'run_date desc' } )->first;
}

1;
Loading

0 comments on commit 071241e

Please sign in to comment.