summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-01-31 21:41:05 +0100
committerfranck cuny <franck@lumberjaph.net>2010-01-31 21:41:05 +0100
commit35132ef3567b569aeb9bc0355983600bbb4e08a6 (patch)
treee2eabe041c8dfc25e1c8fbb2b4091216f882b288
parentstart to gen. gexf (diff)
downloadgithub-explorer-35132ef3567b569aeb9bc0355983600bbb4e08a6.tar.gz
don't check follow(ers|ing) more than once
-rw-r--r--lib/githubexplorer/Profile.pm71
-rw-r--r--lib/githubexplorer/Schema/Result/Profiles.pm3
2 files changed, 44 insertions, 30 deletions
diff --git a/lib/githubexplorer/Profile.pm b/lib/githubexplorer/Profile.pm
index 1f38452..94fe040 100644
--- a/lib/githubexplorer/Profile.pm
+++ b/lib/githubexplorer/Profile.pm
@@ -9,13 +9,11 @@ has banned_profiles =>
sub fetch_profile {
my ( $self, $login, $depth ) = @_;
- return if grep {$_ =~ /$login/i} @{$self->banned_profiles};
- return if $depth > 2;
+ return if grep { $_ =~ /$login/i } @{ $self->banned_profiles };
+ return if $depth > 3;
my $profile = $self->_profile_exists($login);
- return $profile if $profile;
-
say "fetch profile for $login ($depth)...";
my $github = Net::GitHub::V2::Users->new(
owner => $login,
@@ -25,46 +23,61 @@ sub fetch_profile {
sleep(1);
if ( !$profile ) {
+ my $desc = $github->show;
+ if (!$desc || ($desc && exists $desc->{error})) {
+ sleep(60);
+ $self->fetch_profile($login, $depth);
+ }
$profile = $self->_create_profile( $login, $github->show, $depth );
- sleep(1);
+ sleep(2);
if ( $self->with_repo ) {
$self->fetch_repositories( $profile, $github->list );
}
}
- my $followers = $github->followers();
+ my $followers = $github->followers();
sleep(1);
my $following = $github->following();
+ sleep(1);
my $local_depth = $depth + 1;
- foreach my $f (@$followers) {
- my $p = $self->fetch_profile( $f, $local_depth );
- next unless $p;
- $self->schema->txn_do(
- sub {
- $self->schema->resultset('Follow')
- ->find_or_create(
- { id_following => $profile->id, id_follower => $p->id } );
- }
- );
- }
+ unless ( $profile->done ) {
+ foreach my $f (@$followers) {
+ my $p = $self->fetch_profile( $f, $local_depth );
+ next unless $p;
+ $self->schema->txn_do(
+ sub {
+ $self->schema->resultset('Follow')->find_or_create(
+ {
+ id_following => $profile->id,
+ id_follower => $p->id
+ }
+ );
+ }
+ );
+ }
- foreach my $f (@$following) {
- my $p = $self->fetch_profile( $f, $local_depth );
- next unless $p;
- $self->schema->txn_do(
- sub {
- $self->schema->resultset('Follow')
- ->find_or_create(
- { id_following => $p->id, id_follower => $profile->id } );
- },
-
- );
+ foreach my $f (@$following) {
+ my $p = $self->fetch_profile( $f, $local_depth );
+ next unless $p;
+ $self->schema->txn_do(
+ sub {
+ $self->schema->resultset('Follow')->find_or_create(
+ {
+ id_following => $p->id,
+ id_follower => $profile->id
+ }
+ );
+ },
+
+ );
+ }
+ $profile->update( { done => 1 } );
}
+ sleep(1);
$profile;
}
-
sub _profile_exists {
my ( $self, $login ) = @_;
my $profile
diff --git a/lib/githubexplorer/Schema/Result/Profiles.pm b/lib/githubexplorer/Schema/Result/Profiles.pm
index 376103d..e0349d7 100644
--- a/lib/githubexplorer/Schema/Result/Profiles.pm
+++ b/lib/githubexplorer/Schema/Result/Profiles.pm
@@ -18,7 +18,8 @@ __PACKAGE__->add_columns(
name => { data_type => 'varchar', is_nullable => 1 },
public_gist_count => { data_type => 'int' },
public_repo_count => { data_type => 'int' },
- depth => { data_type => 'boolean' },
+ depth => { data_type => 'int' },
+ done => { data_type => 'boolean', default_value => 0 },
perl_total_bytes =>
{ data_type => 'int', is_nullable => 1, default_value => 0 },
);