ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-tags.ext
(Generate patch)

Comparing deliantra/server/ext/map-tags.ext (file contents):
Revision 1.7 by root, Thu Sep 13 16:16:36 2007 UTC vs.
Revision 1.15 by root, Tue Sep 23 04:32:57 2008 UTC

48 48
49 utf8::encode $key; 49 utf8::encode $key;
50 BDB::db_get $db_mapinfo, $txn, $key, my $data; 50 BDB::db_get $db_mapinfo, $txn, $key, my $data;
51 51
52 unless ($!) { 52 unless ($!) {
53 $data = from_json $data; 53 $data = decode_json $data;
54 return if $data->{hash} eq $hash; 54 return if $data->{hash} eq $hash;
55 $old_tags = $data->{tags}; 55 $old_tags = $data->{tags};
56 } 56 }
57 57
58 $old_tags ||= []; 58 $old_tags ||= [];
59 59
60 my $f = new_from_file cf::object::thawer $file 60 my $f = new_from_file cf::object::thawer $file
61 or return; 61 or return;
62 62
63 my @tags = sort $f->extract_tags; 63 my @tags = sort $f->extract_tags;
64 $data = to_json { hash => $hash, tags => \@tags }; 64 $data = encode_json { hash => $hash, tags => \@tags };
65 65
66 BDB::db_put $db_mapinfo, $txn, $key, $data; 66 BDB::db_put $db_mapinfo, $txn, $key, $data;
67 67
68 # 1. remove tags no longer existing 68 # 1. remove tags no longer existing
69 for my $tag (@$old_tags) { 69 for my $tag (@$old_tags) {
79 79
80 # we don't actually care if it succeeds or not, as we 80 # we don't actually care if it succeeds or not, as we
81 # will just retry an hour later 81 # will just retry an hour later
82 BDB::db_txn_finish $txn; 82 BDB::db_txn_finish $txn;
83 83
84# warn "tag-updated $file (= $key) $hash\n";#d# 84 warn "tag-updated $file (= $key) <@tags>\n"
85 if @tags;
85} 86}
86 87
87sub scan_static { 88sub scan_static {
88 my ($dir, $map) = @_; 89 my ($dir, $map) = @_;
89 90
101 &scan_static ("$dir/$_", "$map$_/") 102 &scan_static ("$dir/$_", "$map$_/")
102 for @$dirs; 103 for @$dirs;
103} 104}
104 105
105sub reload { 106sub reload {
107 my $guard = cf::lock_acquire "map-tags::reload";
108
106 my $start = Event::time; 109 my $start = EV::time;
107 110
108 # 1. check for maps no longer existing 111 # 1. check for maps no longer existing
109 { 112 {
110 my @delkeys; 113 my @delkeys;
111 114
112 my $cursor = $db_mapinfo->cursor; 115 my $cursor = $db_mapinfo->cursor;
113 for (;;) { 116 for (;;) {
114 BDB::db_c_get $cursor, my $key, my $data, BDB::NEXT; 117 BDB::db_c_get $cursor, my $key, my $data, BDB::NEXT;
115 last if $!; 118 last if $!;
116 119
117 my $data = JSON::XS::from_json $data; 120 my $data = JSON::XS::decode_json $data;
118 my ($ver, undef, undef, $path) = split /,/, $data->{hash}, 4; 121 my ($ver, undef, undef, $path) = split /,/, $data->{hash}, 4;
119 push @delkeys, [$key, $data->{tags}] 122 push @delkeys, [$key, $data->{tags}]
120 if $ver != 1 || Coro::AIO::aio_stat $path; 123 if $ver != 1 || Coro::AIO::aio_stat $path;
121 } 124 }
122 BDB::db_c_close $cursor; 125 BDB::db_c_close $cursor;
166# delete $map->{deny_reset}; 169# delete $map->{deny_reset};
167# } 170# }
168# } 171# }
169# } 172# }
170 173
171 warn sprintf "map-tag scan (%fs)", Event::time - $start; 174 warn sprintf "map-tag scan (%fs)", EV::time - $start;
172} 175}
173 176
174our $RELOAD_SCHEDULER = Event->timer ( 177our $RELOAD_SCHEDULER = cf::periodic $SCHEDULE_INTERVAL, Coro::unblock_sub {
175 after => 0,
176 interval => $SCHEDULE_INTERVAL,
177 data => cf::WF_AUTOCANCEL,
178 cb => Coro::unblock_sub {
179 $Coro::current->prio (Coro::PRIO_MIN); 178 $Coro::current->prio (Coro::PRIO_MIN);
179 $Coro::current->desc ("map-tag scanner");
180 reload; 180 reload;
181 }, 181};
182); 182
183cf::post_init {
184 $RELOAD_SCHEDULER->invoke (0); # force at startup
185};
183 186
184# find all objects with the given tag, or at least try to 187# find all objects with the given tag, or at least try to
185sub find($) { 188sub find($) {
186 my ($tag) = @_; 189 my ($tag) = @_;
187 190

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines