--- deliantra/server/ext/map-tags.ext 2009/10/23 03:08:34 1.17 +++ deliantra/server/ext/map-tags.ext 2009/10/25 10:05:20 1.20 @@ -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,7 +79,7 @@ sub scan_static { my $maps = cf::map::static_maps; - scan_map "s$_", "$cf::MAPDIR$_.map"; + scan_map "s$_", "$cf::MAPDIR$_.map" for @$maps; } @@ -187,3 +178,10 @@ grep s/^s//, split /\x00/, $data } + +sub unload { + my $guard = cf::lock_acquire "map-tags::reload"; + + db_close $db_target; + db_close $db_mapinfo; +}