X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FMiscIdx.pm;h=19200b92c910c8e22de43acccdbf1bd9e89fa0e6;hb=e28f33dc1b6e6a296946c0c58b43900c6cbd07f7;hp=a04dd1c532168fcf13627a17abfa2fae75b8ecb5;hpb=8862c33ae93eea1af6246cd3c7a81e0a122186bf;p=public-inbox.git
diff --git a/lib/PublicInbox/MiscIdx.pm b/lib/PublicInbox/MiscIdx.pm
index a04dd1c5..19200b92 100644
--- a/lib/PublicInbox/MiscIdx.pm
+++ b/lib/PublicInbox/MiscIdx.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
# like PublicInbox::SearchIdx, but for searching for non-mail messages.
@@ -16,11 +16,11 @@ use v5.10.1;
use PublicInbox::InboxWritable;
use PublicInbox::Search; # for SWIG Xapian and Search::Xapian compat
use PublicInbox::SearchIdx qw(index_text term_generator add_val);
-use PublicInbox::Spawn qw(nodatacow_dir);
use Carp qw(croak);
use File::Path ();
use PublicInbox::MiscSearch;
use PublicInbox::Config;
+use PublicInbox::Syscall;
my $json;
sub new {
@@ -28,9 +28,10 @@ sub new {
PublicInbox::SearchIdx::load_xapian_writable();
my $mi_dir = "$eidx->{xpfx}/misc";
File::Path::mkpath($mi_dir);
- nodatacow_dir($mi_dir);
+ PublicInbox::Syscall::nodatacow_dir($mi_dir);
my $flags = $PublicInbox::SearchIdx::DB_CREATE_OR_OPEN;
$flags |= $PublicInbox::SearchIdx::DB_NO_SYNC if $eidx->{-no_fsync};
+ $flags |= $PublicInbox::SearchIdx::DB_DANGEROUS if $eidx->{-dangerous};
$json //= PublicInbox::Config::json();
bless {
mi_dir => $mi_dir,
@@ -39,25 +40,30 @@ sub new {
}, $class;
}
-sub begin_txn {
+sub _begin_txn ($) {
my ($self) = @_;
- croak 'BUG: already in txn' if $self->{xdb}; # XXX make lazy?
my $wdb = $PublicInbox::Search::X{WritableDatabase};
my $xdb = eval { $wdb->new($self->{mi_dir}, $self->{flags}) };
croak "Failed opening $self->{mi_dir}: $@" if $@;
- $self->{xdb} = $xdb;
$xdb->begin_transaction;
+ $xdb;
}
sub commit_txn {
my ($self) = @_;
- croak 'BUG: not in txn' unless $self->{xdb}; # XXX make lazy?
- delete($self->{xdb})->commit_transaction;
+ my $xdb = delete $self->{xdb} or return;
+ $xdb->commit_transaction;
+}
+
+sub create_xdb {
+ my ($self) = @_;
+ $self->{xdb} //= _begin_txn($self);
+ commit_txn($self);
}
sub remove_eidx_key {
my ($self, $eidx_key) = @_;
- my $xdb = $self->{xdb};
+ my $xdb = $self->{xdb} //= _begin_txn($self);
my $head = $xdb->postlist_begin('Q'.$eidx_key);
my $tail = $xdb->postlist_end('Q'.$eidx_key);
my @docids; # only one, unless we had bugs
@@ -66,7 +72,7 @@ sub remove_eidx_key {
}
for my $docid (@docids) {
$xdb->delete_document($docid);
- warn "I: remove inbox docid #$docid ($eidx_key)\n";
+ warn "# remove inbox docid #$docid ($eidx_key)\n";
}
}
@@ -74,7 +80,7 @@ sub remove_eidx_key {
sub index_ibx {
my ($self, $ibx) = @_;
my $eidx_key = $ibx->eidx_key;
- my $xdb = $self->{xdb};
+ my $xdb = $self->{xdb} //= _begin_txn($self);
# Q = uniQue in Xapian terminology
my $head = $xdb->postlist_begin('Q'.$eidx_key);
my $tail = $xdb->postlist_end('Q'.$eidx_key);
@@ -102,12 +108,16 @@ EOF
$doc->add_boolean_term('Q'.$eidx_key); # uniQue id
$doc->add_boolean_term('T'.'inbox'); # Type
+ # force reread from disk, {description} could be loaded from {misc}
+ delete @$ibx{qw(-art_min -art_max description)};
if (defined($ibx->{newsgroup}) && $ibx->nntp_usable) {
$doc->add_boolean_term('T'.'newsgroup'); # additional Type
+ my $n = $ibx->art_min;
+ add_val($doc, $PublicInbox::MiscSearch::ART_MIN, $n) if $n;
+ $n = $ibx->art_max;
+ add_val($doc, $PublicInbox::MiscSearch::ART_MAX, $n) if $n;
}
- # force reread from disk, {description} could be loaded from {misc}
- delete $ibx->{description};
my $desc = $ibx->description;
# description = S/Subject (or title)