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.18 by root, Fri Oct 23 03:28:11 2009 UTC vs.
Revision 1.19 by root, Sat Oct 24 00:25:26 2009 UTC

40 Coro::AIO::aio_stat $file 40 Coro::AIO::aio_stat $file
41 and next; 41 and next;
42 42
43 my $hash = join ",", 1, (stat _)[7,9], $file; 43 my $hash = join ",", 1, (stat _)[7,9], $file;
44 44
45 my $old_tags;
46
47 my $txn = $cf::DB_ENV->txn_begin; 45 my $txn = $cf::DB_ENV->txn_begin;
48 46
49 utf8::encode $key; 47 utf8::encode $key;
50 BDB::db_get $db_mapinfo, $txn, $key, my $data; 48 BDB::db_get $db_mapinfo, $txn, $key, my $data;
51 49
52 unless ($!) { 50 unless ($!) {
53 $data = decode_json $data; 51 $data = decode_json $data;
54 return if $data->{hash} eq $hash; 52 return if $data->{hash} eq $hash;
55 $old_tags = $data->{tags}; 53
54 # remove all old tags unconditionally
55 remove_tag_target $txn, $_, $key
56 for @{ $data->{tags} };
56 } 57 }
57
58 $old_tags ||= [];
59 58
60 my $f = new_from_file cf::object::thawer $file 59 my $f = new_from_file cf::object::thawer $file
61 or return; 60 or return;
62 61
63 my @tags = sort $f->extract_tags; 62 my @tags = sort $f->extract_tags;
64 $data = encode_json { hash => $hash, tags => \@tags }; 63 $data = encode_json { hash => $hash, tags => \@tags };
65 64
66 BDB::db_put $db_mapinfo, $txn, $key, $data; 65 BDB::db_put $db_mapinfo, $txn, $key, $data;
67 66
68 # 1. remove tags no longer existing 67 # add all tags
69 for my $tag (@$old_tags) {
70 next if grep $_ eq $tag, @tags;
71 remove_tag_target $txn, $tag, $key;
72 }
73
74 # 2. add tags that are new
75 for my $tag (@tags) {
76 next if grep $_ eq $tag, @$old_tags;
77 add_tag_target $txn, $tag, $key; 68 add_tag_target $txn, $_, $key
78 } 69 for @tags;
79 70
80 # we don't actually care if it succeeds or not, as we 71 # we don't actually care if it succeeds or not, as we
81 # will just retry an hour later 72 # will just retry an hour later
82 BDB::db_txn_finish $txn; 73 BDB::db_txn_finish $txn;
83 74

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines