diff options
author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2007-11-27 01:00:09 +0100 |
---|---|---|
committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2007-11-27 01:00:09 +0100 |
commit | a103e43763ec859782928d74833aca343fdaccea (patch) | |
tree | 51d89624b410a5cab5dcc514406a195ef9c1c581 | |
parent | 5b3f52e26d53d40c1da454b175c71f4155d5f15c (diff) |
Flush only in parent process.
-rw-r--r-- | lib/LXRng/Search/Xapian.pm | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/LXRng/Search/Xapian.pm b/lib/LXRng/Search/Xapian.pm index b6e28a0..ef6f0fb 100644 --- a/lib/LXRng/Search/Xapian.pm +++ b/lib/LXRng/Search/Xapian.pm @@ -19,7 +19,11 @@ sub new { sub wrdb { my ($self) = @_; - return $$self{'wrdb'} ||= Search::Xapian::WritableDatabase + return $$self{'wrdb'} if $$self{'wrdb'}; + + $$self{'wrdb_pid'} = $$; + + return $$self{'wrdb'} = Search::Xapian::WritableDatabase ->new($$self{'db_root'}, Search::Xapian::DB_CREATE_OR_OPEN); } @@ -68,7 +72,7 @@ sub add_release { sub flush { my ($self) = @_; - warn "\n*** hash: flushing\n"; + warn "*** hash: flushing\n"; $self->wrdb->flush(); } @@ -153,7 +157,14 @@ sub reset_db { sub DESTROY { my ($self) = @_; - $self->flush() if $self->{'writes'} > 0; + if ($self->{'writes'} > 0) { + if ($$self{'wrdb_pid'} != $$) { + undef $$self{'wrdb'}; + } + else { + $self->flush(); + } + } } 1; |