diff scan.pl @ 20:5635e75c92d0

the user profile is also cached for 1 hour.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 16:56:22 +0800
parents fd44e3a1f800
children 552528bb4917
line wrap: on
line diff
--- a/scan.pl	Wed Oct 08 16:22:54 2008 +0800
+++ b/scan.pl	Wed Oct 08 16:56:22 2008 +0800
@@ -27,12 +27,16 @@
         }
 
         printf("city %d %s saved\n", $city->{cityId}, $city->{cityname});
-
-        # Download user profile.
-        foreach my $x (qw/score army_score_main trader_score_secondary/)
+        if(my $user = Ikariam::User->retrieve($city->{user}))
         {
-            my $users = $::i->viewScore($x, $city->{owner}, 0);
-            saveUser($users);
+            if($user->time le (time - 60*60)) {
+                # Download user profile.
+                foreach my $x (qw/score army_score_main trader_score_secondary/)
+                {
+                    my $users = $::i->viewScore($x, $city->{owner}, 0);
+                    saveUser($users);
+                }
+            }
         }
     }
 }
@@ -41,21 +45,22 @@
 {
     my $users = shift;
 
-    foreach my $user (values(%{$users}))
+    foreach my $h_user (values(%{$users}))
     {
         # print(Dumper($user));
-        printf("Saving user %s\n", $user->{'name'});
-        $user->{'time'} = time;
-        if(my $c = Ikariam::User->retrieve($user->{id}))
+        printf("Saving user %s\n", $h_user->{'name'});
+        $h_user->{'time'} = time;
+        my $user;
+        if($user = Ikariam::User->retrieve($h_user->{id}))
         {
-            foreach my $i (keys(%$user)) {
-                eval($c->$i($user->{$i}));
+            foreach my $i (keys(%$h_user)) {
+                # eval($c->$i($h_user->{$i}));
+                $user->set($i => $h_user->{$i});
             }
-            $c->autoupdate(1);
-            $c->update();
         } else {
-            Ikariam::User->insert($user);
+            $user = Ikariam::User->insert($h_user);
         }
+        $user->update();
     }
 }