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.4 by root, Tue Sep 11 15:40:01 2007 UTC vs.
Revision 1.11 by root, Wed Nov 14 10:05:16 2007 UTC

77 add_tag_target $txn, $tag, $key; 77 add_tag_target $txn, $tag, $key;
78 } 78 }
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_commit $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
100 101
101 &scan_static ("$dir/$_", "$map$_/") 102 &scan_static ("$dir/$_", "$map$_/")
102 for @$dirs; 103 for @$dirs;
103} 104}
104 105
105cf::async_ext { 106sub reload {
106 $Coro::current->prio (Coro::PRIO_MIN); 107 my $guard = cf::lock_acquire "map-tags::reload";
107 108
108 while () {
109 my $start = Event::time; 109 my $start = EV::time;
110 110
111 # 1. check for maps no longer existing 111 # 1. check for maps no longer existing
112 {
113 my @delkeys;
112 114
113 # 2. scan all static maps 115 my $cursor = $db_mapinfo->cursor;
114 scan_static $cf::MAPDIR, "/"; 116 for (;;) {
117 BDB::db_c_get $cursor, my $key, my $data, BDB::NEXT;
118 last if $!;
115 119
120 my $data = JSON::XS::from_json $data;
121 my ($ver, undef, undef, $path) = split /,/, $data->{hash}, 4;
122 push @delkeys, [$key, $data->{tags}]
123 if $ver != 1 || Coro::AIO::aio_stat $path;
124 }
125 BDB::db_c_close $cursor;
126
127 for (@delkeys) {
128 my ($key, $tags) = @$_;
129 my $txn = $cf::DB_ENV->txn_begin;
130 BDB::db_del $db_mapinfo, $txn, $key;
131 for my $tag (@{ $tags || [] }) {
132 remove_tag_target $txn, $tag, $key;
133 }
134 BDB::db_txn_finish $txn;
135 }
136 }
137
138 # 2. scan all static maps
139 scan_static $cf::MAPDIR, "/";
140
116 # 3. scan all dynamic maps 141 # 3. scan all dynamic maps
117 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) { 142 for my $path (@{ cf::map::tmp_maps or [] }, @{ cf::map::random_maps or [] }) {
118# my $map = cf::map::find $path; 143# my $map = cf::map::find $path;
119# extract_map_tags "t/$map", $path; 144# extract_map_tags "t/$map", $path;
120 } 145 }
121 146
122 # now hunt for all per-player maps 147 # now hunt for all per-player maps
123# scan_dir $cf::PLAYERDIR 148# scan_dir $cf::PLAYERDIR
124# for my $login (@{ cf::player::list_logins or [] }) { 149# for my $login (@{ cf::player::list_logins or [] }) {
125# for my $path (@{ cf::player::maps $login or [] }) { 150# for my $path (@{ cf::player::maps $login or [] }) {
126# cf::cede_to_tick; 151# cf::cede_to_tick;
144# delete $map->{deny_reset}; 169# delete $map->{deny_reset};
145# } 170# }
146# } 171# }
147# } 172# }
148 173
149 warn sprintf "map-tag scan (%fs)", Event::time - $start; 174 warn sprintf "map-tag scan (%fs)", EV::time - $start;
150 Coro::Timer::sleep $SCHEDULE_INTERVAL; 175}
151 } 176
177our $RELOAD_SCHEDULER = cf::periodic $SCHEDULE_INTERVAL, Coro::unblock_sub {
178 $Coro::current->prio (Coro::PRIO_MIN);
179 $Coro::current->desc ("map-tag scanner");
180 reload;
152}; 181};
153 182
183# find all objects with the given tag, or at least try to
154sub find($) { 184sub find($) {
155 my ($tag) = @_; 185 my ($tag) = @_;
156 186
157 utf8::encode (my $key = $tag); 187 utf8::encode (my $key = $tag);
158 BDB::db_get $db_target, undef, $key, my $data; 188 BDB::db_get $db_target, undef, $key, my $data;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines