--- deliantra/server/ext/map-tags.ext 2009/10/23 03:08:34 1.17 +++ deliantra/server/ext/map-tags.ext 2010/04/22 12:50:24 1.23 @@ -42,8 +42,6 @@ my $hash = join ",", 1, (stat _)[7,9], $file; - my $old_tags; - my $txn = $cf::DB_ENV->txn_begin; utf8::encode $key; @@ -52,10 +50,11 @@ unless ($!) { $data = decode_json $data; return if $data->{hash} eq $hash; - $old_tags = $data->{tags}; - } - $old_tags ||= []; + # remove all old tags unconditionally + remove_tag_target $txn, $_, $key + for @{ $data->{tags} }; + } my $f = new_from_file cf::object::thawer $file or return; @@ -65,17 +64,9 @@ BDB::db_put $db_mapinfo, $txn, $key, $data; - # 1. remove tags no longer existing - for my $tag (@$old_tags) { - next if grep $_ eq $tag, @tags; - remove_tag_target $txn, $tag, $key; - } - - # 2. add tags that are new - for my $tag (@tags) { - next if grep $_ eq $tag, @$old_tags; - add_tag_target $txn, $tag, $key; - } + # add all tags + add_tag_target $txn, $_, $key + for @tags; # we don't actually care if it succeeds or not, as we # will just retry an hour later @@ -88,14 +79,14 @@ sub scan_static { my $maps = cf::map::static_maps; - scan_map "s$_", "$cf::MAPDIR$_.map"; + scan_map "s$_", "$cf::MAPDIR$_.map" for @$maps; } sub reload { my $guard = cf::lock_acquire "map-tags::reload"; - my $start = EV::time; + my $start = AE::time; # 1. check for maps no longer existing { @@ -160,7 +151,7 @@ # } # } - warn sprintf "map-tag scan (%fs)", EV::time - $start; + warn sprintf "map-tag scan finished (%fs)\n", AE::time - $start; } our $RELOAD_SCHEDULER = cf::periodic $SCHEDULE_INTERVAL, Coro::unblock_sub { @@ -187,3 +178,10 @@ grep s/^s//, split /\x00/, $data } + +sub unload { + my $guard = cf::lock_acquire "map-tags::reload"; + + BDB::db_close $db_target; + BDB::db_close $db_mapinfo; +}