From 8b4f40d0b79736a73704a5bacd8a5d6be50d3f96 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sat, 23 Jan 2010 20:28:01 +0100 Subject: count perl bytes, some tweaking --- lib/githubexplorer/Profile.pm | 23 +++++++++++++++++------ lib/githubexplorer/Repositorie.pm | 21 ++++++++++++++------- lib/githubexplorer/Schema/Result/Profiles.pm | 2 ++ 3 files changed, 33 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/githubexplorer/Profile.pm b/lib/githubexplorer/Profile.pm index d4024df..47a0582 100644 --- a/lib/githubexplorer/Profile.pm +++ b/lib/githubexplorer/Profile.pm @@ -6,7 +6,7 @@ use Net::GitHub::V2::Users; sub fetch_profile { my ( $self, $login, $depth ) = @_; - return if $depth > 2; + return if $depth > 3; my $profile = $self->_profile_exists($login); say "fetch profile for $login ($depth)..."; @@ -32,9 +32,13 @@ sub fetch_profile { foreach my $f (@$followers) { my $p = $self->fetch_profile( $f, $local_depth ); next unless $p; - $self->schema->resultset('Follow') - ->create( - { id_following => $profile->id, id_follower => $p->id } ); + $self->schema->txn_do( + sub { + $self->schema->resultset('Follow') + ->find_or_create( + { id_following => $profile->id, id_follower => $p->id } ); + } + ); } $profile; } @@ -51,8 +55,15 @@ sub _create_profile { $profile->{depth} = $depth; - my $profile_rs = $self->schema->resultset('Profiles')->create($profile); - say $profile_rs->login."'s profile created"; + my $profile_rs; + + $self->schema->txn_do( + sub { + $profile_rs + = $self->schema->resultset('Profiles')->create($profile); + } + ); + say '-> '.$profile_rs->login . "'s profile created"; return $profile_rs; } diff --git a/lib/githubexplorer/Repositorie.pm b/lib/githubexplorer/Repositorie.pm index 907a3b8..6d777b8 100644 --- a/lib/githubexplorer/Repositorie.pm +++ b/lib/githubexplorer/Repositorie.pm @@ -6,9 +6,9 @@ use Net::GitHub::V2::Repositories; sub fetch_repo { my ( $self, $profile, $repo_name ) = @_; - return if $self->_repo_exists($profile, $repo_name); + return if $self->_repo_exists( $profile, $repo_name ); - say "check ".$profile->login."'s $repo_name"; + say "-> check " . $profile->login . "'s $repo_name"; sleep(1); my $github = Net::GitHub::V2::Repositories->new( owner => $profile->login, @@ -16,11 +16,14 @@ sub fetch_repo { login => $self->api_login, token => $self->api_token, ); - my $langs = [ keys %{ $github->languages() } ]; sleep(1); - return unless grep {/perl/i} @$langs; + my $langs = $github->languages(); + sleep(1); + return unless grep {/perl/i} keys %$langs; my $repo_desc = $github->show(); - $repo_desc->{languages} = $langs; + sleep(1); + $profile->perl_total_bytes( $profile->perl_total_bytes + $langs->{Perl} ); + $self->schema->txn_do( sub { $profile->update } ); $self->_create_repo( $profile, $repo_desc ); sleep(1); } @@ -43,8 +46,12 @@ sub _create_repo { map { $_ => $repo_desc->{$_} } (qw/description name homepage url watchers forks/) }; - $repo_rs - = $self->schema->resultset('Repositories')->create($repo_insert); + $self->schema->txn_do( + sub { + $repo_rs = $self->schema->resultset('Repositories') + ->create($repo_insert); + } + ); } $repo_rs; } diff --git a/lib/githubexplorer/Schema/Result/Profiles.pm b/lib/githubexplorer/Schema/Result/Profiles.pm index 001057e..376103d 100644 --- a/lib/githubexplorer/Schema/Result/Profiles.pm +++ b/lib/githubexplorer/Schema/Result/Profiles.pm @@ -19,6 +19,8 @@ __PACKAGE__->add_columns( public_gist_count => { data_type => 'int' }, public_repo_count => { data_type => 'int' }, depth => { data_type => 'boolean' }, + perl_total_bytes => + { data_type => 'int', is_nullable => 1, default_value => 0 }, ); __PACKAGE__->set_primary_key('id'); -- cgit 1.4.1