summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-01-31 22:11:38 +0100
committerfranck cuny <franck@lumberjaph.net>2010-01-31 22:11:38 +0100
commite0fcff8a5adde1505dd64b3a338d8b11c75d84af (patch)
treea6db6ba93ef4b98347730ca8e7104d9f4d157cc5 /lib
parentdon't check follow(ers|ing) more than once (diff)
downloadgithub-explorer-e0fcff8a5adde1505dd64b3a338d8b11c75d84af.tar.gz
wip
Diffstat (limited to 'lib')
-rw-r--r--lib/githubexplorer/Profile.pm101
1 files changed, 63 insertions, 38 deletions
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 {