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.8 by root, Mon Sep 17 11:45:41 2007 UTC vs.
Revision 1.18 by root, Fri Oct 23 03:28:11 2009 UTC

2 2
3our $SCHEDULE_INTERVAL = $cf::CFG{extractor_schedule_interval} || 3600; 3our $SCHEDULE_INTERVAL = $cf::CFG{extractor_schedule_interval} || 3600;
4 4
5use JSON::XS; 5use JSON::XS;
6 6
7my $db_mapinfo = cf::sync_job { cf::db_table "tag-mapinfo" }; # info/cache for maps 7our $db_mapinfo = cf::sync_job { cf::db_table "tag-mapinfo" }; # info/cache for maps
8my $db_target = cf::sync_job { cf::db_table "tag-target" }; # tag => maps 8our $db_target = cf::sync_job { cf::db_table "tag-target" }; # tag => maps
9 9
10sub remove_tag_target { 10sub remove_tag_target {
11 my ($txn, $tag, $target) = @_; 11 my ($txn, $tag, $target) = @_;
12 # - U O 12 # - U O
13 13
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) {
84 warn "tag-updated $file (= $key) <@tags>\n" 84 warn "tag-updated $file (= $key) <@tags>\n"
85 if @tags; 85 if @tags;
86} 86}
87 87
88sub scan_static { 88sub scan_static {
89 my ($dir, $map) = @_; 89 my $maps = cf::map::static_maps;
90 90
91 my ($dirs, $files) = Coro::AIO::aio_scandir $dir, 2 91 scan_map "s$_", "$cf::MAPDIR$_.map"
92 or return;
93
94 for my $file (@$files) {
95 my $name = $file;
96 next unless $name =~ s/\.map$//;
97 utf8::decode $name;
98
99 scan_map "s$map$name", "$dir/$file";
100 }
101
102 &scan_static ("$dir/$_", "$map$_/")
103 for @$dirs; 92 for @$maps;
104} 93}
105 94
106sub reload { 95sub reload {
107 my $guard = cf::lock_acquire "map-tags::reload"; 96 my $guard = cf::lock_acquire "map-tags::reload";
108 97
109 my $start = Event::time; 98 my $start = EV::time;
110 99
111 # 1. check for maps no longer existing 100 # 1. check for maps no longer existing
112 { 101 {
113 my @delkeys; 102 my @delkeys;
114 103
115 my $cursor = $db_mapinfo->cursor; 104 my $cursor = $db_mapinfo->cursor;
116 for (;;) { 105 for (;;) {
117 BDB::db_c_get $cursor, my $key, my $data, BDB::NEXT; 106 BDB::db_c_get $cursor, my $key, my $data, BDB::NEXT;
118 last if $!; 107 last if $!;
119 108
120 my $data = JSON::XS::from_json $data; 109 my $data = JSON::XS::decode_json $data;
121 my ($ver, undef, undef, $path) = split /,/, $data->{hash}, 4; 110 my ($ver, undef, undef, $path) = split /,/, $data->{hash}, 4;
122 push @delkeys, [$key, $data->{tags}] 111 push @delkeys, [$key, $data->{tags}]
123 if $ver != 1 || Coro::AIO::aio_stat $path; 112 if $ver != 1 || Coro::AIO::aio_stat $path;
124 } 113 }
125 BDB::db_c_close $cursor; 114 BDB::db_c_close $cursor;
169# delete $map->{deny_reset}; 158# delete $map->{deny_reset};
170# } 159# }
171# } 160# }
172# } 161# }
173 162
174 warn sprintf "map-tag scan (%fs)", Event::time - $start; 163 warn sprintf "map-tag scan (%fs)", EV::time - $start;
175} 164}
176 165
177our $RELOAD_SCHEDULER = Event->timer ( 166our $RELOAD_SCHEDULER = cf::periodic $SCHEDULE_INTERVAL, Coro::unblock_sub {
178 after => 0,
179 interval => $SCHEDULE_INTERVAL,
180 data => cf::WF_AUTOCANCEL,
181 cb => Coro::unblock_sub {
182 $Coro::current->prio (Coro::PRIO_MIN); 167 $Coro::current->prio (Coro::PRIO_MIN);
168 $Coro::current->desc ("map-tag scanner");
183 reload; 169 reload;
184 }, 170};
185); 171
172cf::post_init {
173 $RELOAD_SCHEDULER->invoke (0); # force at startup
174};
186 175
187# find all objects with the given tag, or at least try to 176# find all objects with the given tag, or at least try to
188sub find($) { 177sub find($) {
189 my ($tag) = @_; 178 my ($tag) = @_;
190 179

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines