From e0fcff8a5adde1505dd64b3a338d8b11c75d84af Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sun, 31 Jan 2010 22:11:38 +0100 Subject: wip --- lib/githubexplorer/Profile.pm | 101 ++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 38 deletions(-) (limited to 'lib/githubexplorer') diff --git a/lib/githubexplorer/Profile.pm b/lib/githubexplorer/Profile.pm index 94fe040..d9579e4 100644 --- a/lib/githubexplorer/Profile.pm +++ b/lib/githubexplorer/Profile.pm @@ -23,6 +23,7 @@ sub fetch_profile { sleep(1); if ( !$profile ) { + return if $depth > 3; my $desc = $github->show; if (!$desc || ($desc && exists $desc->{error})) { sleep(60); @@ -35,47 +36,71 @@ sub fetch_profile { } } - my $followers = $github->followers(); - sleep(1); my $following = $github->following(); - sleep(1); - my $local_depth = $depth + 1; - - 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) { + if (my $p = $self->schema->resultset('Profiles')->find({login => $f})) { + $self->schema->txn_do( + sub { + $self->schema->resultset('Follow')->find_or_create( + { + id_following => $p->id, + id_follower => $profile->id + } + ); + }, + + ); + }else{ + say "need to fetch $f"; } - $profile->update( { done => 1 } ); +# say "$login follow $f"; +# my $p = $self->fetch_profile( $f, $local_depth ); +# next unless $p; } - sleep(1); - $profile; + +# unless ( $profile->done ) { +# my $followers = $github->followers(); +# sleep(1); +# my $following = $github->following(); +# sleep(1); +# my $local_depth = $depth + 1; +# foreach my $f (@$followers) { +# say "$login is followed by $f"; +# 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) { +# say "$login follow $f"; +# 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 +# } +# ); +# }, +# +# ); +# } +# say "update profile for $login: done"; +# $profile->update( { done => 1 } ); +# } +# sleep(1); +# $profile; } sub _profile_exists { -- cgit 1.4.1