]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
searchidx: v1: raise on msgmap init failure
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 78db329d9da9145ff97091004265ce9264231aca..b886ce789b7943dfb5eb2c248bb62c6329e36acc 100644 (file)
@@ -451,10 +451,9 @@ sub add_xapian ($$$$) {
 sub _msgmap_init ($) {
        my ($self) = @_;
        die "BUG: _msgmap_init is only for v1\n" if $self->{ibx}->version != 1;
-       $self->{mm} //= eval {
+       $self->{mm} //= do {
                require PublicInbox::Msgmap;
-               my $rw = $self->{ibx}->{-no_fsync} ? 2 : 1;
-               PublicInbox::Msgmap->new($self->{ibx}->{inboxdir}, $rw);
+               PublicInbox::Msgmap->new_file($self->{ibx}, 1);
        };
 }
 
@@ -518,6 +517,12 @@ sub add_eidx_info {
        $self->{xdb}->replace_document($docid, $doc);
 }
 
+sub get_terms {
+       my ($self, $pfx, $docid) = @_;
+       begin_txn_lazy($self);
+       xap_terms($pfx, $self->{xdb}, $docid);
+}
+
 sub remove_eidx_info {
        my ($self, $docid, $eidx_key, $eml) = @_;
        begin_txn_lazy($self);
@@ -650,8 +655,11 @@ sub xdb_remove_quiet {
        begin_txn_lazy($self);
        my $xdb = $self->{xdb} // die 'BUG: missing {xdb}';
        eval { $xdb->delete_document($docid) };
+       ++$self->{-quiet_rm} unless $@;
 }
 
+sub nr_quiet_rm { delete($_[0]->{-quiet_rm}) // 0 }
+
 sub index_git_blob_id {
        my ($doc, $pfx, $objid) = @_;
 
@@ -791,6 +799,7 @@ sub v1_checkpoint ($$;$) {
        ${$sync->{max}} = $self->{batch_bytes};
 
        $self->{mm}->{dbh}->commit;
+       eval { $self->{mm}->{dbh}->do('PRAGMA optimize') };
        my $xdb = $self->{xdb};
        if ($newest && $xdb) {
                my $cur = $xdb->get_metadata('last_commit');