about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Admin.pm25
-rw-r--r--lib/PublicInbox/SearchIdx.pm8
-rw-r--r--lib/PublicInbox/Xapcmd.pm8
3 files changed, 41 insertions, 0 deletions
diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index 07d8b572..4a862c6d 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -41,6 +41,31 @@ sub resolve_repo_dir {
         }
 }
 
+# for unconfigured inboxes
+sub detect_indexlevel ($) {
+        my ($ibx) = @_;
+
+        # brand new or never before indexed inboxes default to full
+        return 'full' unless $ibx->over;
+        delete $ibx->{over}; # don't leave open FD lying around
+
+        my $l = 'basic';
+        my $srch = $ibx->search or return $l;
+        delete $ibx->{search}; # don't leave open FD lying around
+        if (my $xdb = $srch->xdb) {
+                $l = 'full';
+                my $m = $xdb->get_metadata('indexlevel');
+                if ($m eq 'medium') {
+                        $l = $m;
+                } elsif ($m ne '') {
+                        warn <<"";
+$ibx->{mainrepo} has unexpected indexlevel in Xapian: $m
+
+                }
+        }
+        $l;
+}
+
 sub resolve_inboxes {
         my ($argv, $warn_on_unconfigured) = @_;
         require PublicInbox::Config;
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index b963805e..99856286 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -828,6 +828,14 @@ sub commit_txn_lazy {
         delete $self->{txn} or return;
         $self->{-inbox}->with_umask(sub {
                 if (my $xdb = $self->{xdb}) {
+
+                        # store 'indexlevel=medium' in v2 part=0 and v1 (only part)
+                        # This metadata is read by Admin::detect_indexlevel:
+                        if (!$self->{partition} # undef or 0, not >0
+                            && $self->{indexlevel} eq 'medium') {
+                                $xdb->set_metadata('indexlevel', 'medium');
+                        }
+
                         $xdb->commit_transaction;
                 }
                 $self->{over}->commit_lazy if $self->{over};
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 7e3d47fb..90672310 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -275,6 +275,14 @@ sub cpdb ($$) {
                         my $lc = $src->get_metadata('last_commit');
                         $dst->set_metadata('last_commit', $lc) if $lc;
 
+                        # only the first xapian partition (0) gets 'indexlevel'
+                        if ($old =~ m!(?:xapian\d+|xap\d+/0)\z!) {
+                                my $l = $src->get_metadata('indexlevel');
+                                if ($l eq 'medium') {
+                                        $dst->set_metadata('indexlevel', $l);
+                                }
+                        }
+
                         $it = $src->postlist_begin('');
                         $end = $src->postlist_end('');
                         if ($pr) {