comparison scan.pl @ 16:59f2c435760c

implemented cached by timing.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 15:24:21 +0800
parents 8b7bc598ba06
children fd44e3a1f800
comparison
equal deleted inserted replaced
15:e68f4cadfabd 16:59f2c435760c
9 my ($island, @cities) = @_; 9 my ($island, @cities) = @_;
10 10
11 foreach my $city (@cities) 11 foreach my $city (@cities)
12 { 12 {
13 $city->{island} = $island; 13 $city->{island} = $island;
14 $city->{'time'} = time;
14 if(my $c = Ikariam::Cities->retrieve($city->{cityId})) 15 if(my $c = Ikariam::Cities->retrieve($city->{cityId}))
15 { 16 {
16 foreach my $i (keys(%$city)) { 17 foreach my $i (keys(%$city)) {
17 eval($c->$i($city->{$i})); 18 eval($c->$i($city->{$i}));
18 # printf("%s %s ", $i, $city->{$i}); 19 # printf("%s %s ", $i, $city->{$i});
42 43
43 foreach my $user (values(%{$users})) 44 foreach my $user (values(%{$users}))
44 { 45 {
45 # print(Dumper($user)); 46 # print(Dumper($user));
46 printf("Saving user %s\n", $user->{'name'}); 47 printf("Saving user %s\n", $user->{'name'});
48 $user->{'time'} = time;
47 if(my $c = Ikariam::User->retrieve($user->{id})) 49 if(my $c = Ikariam::User->retrieve($user->{id}))
48 { 50 {
49 foreach my $i (keys(%$user)) { 51 foreach my $i (keys(%$user)) {
50 eval($c->$i($user->{$i})); 52 eval($c->$i($user->{$i}));
51 } 53 }
79 } 81 }
80 82
81 foreach my $island (@islands) 83 foreach my $island (@islands)
82 { 84 {
83 printf("checking island %d\n", $island->{id}); 85 printf("checking island %d\n", $island->{id});
84 if(my $c = Ikariam::Island->retrieve($island->{id})) {
85 foreach my $i (keys(%$island)) {
86 eval($c->$i($island->{$i}));
87 }
88 } else {
89 Ikariam::Island->insert($island);
90 }
91 86
92 # scanning the island 87 # scanning the island
93 my @cities = $i->viewIsland($island->{id}); 88 if($island->{time} < (time - 60*60*12 ))
94 saveCities($island->{id}, @cities); 89 {
90 my @cities = $i->viewIsland($island->{id});
91 saveCities($island->{id}, @cities);
92
93 $island->{'time'} = time;
94 if(my $c = Ikariam::Island->retrieve($island->{id})) {
95 foreach my $i (keys(%$island)) {
96 eval($c->$i($island->{$i}));
97 }
98 } else {
99 Ikariam::Island->insert($island);
100 }
101 }
95 } 102 }
96 $i->logout; 103 $i->logout;
97 # $i->getCityInfo(); 104 # $i->getCityInfo();