]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Xapcmd.pm
searchidx: store indexlevel=medium as metadata
[public-inbox.git] / lib / PublicInbox / Xapcmd.pm
index 999819c74b6ccb52eac4de475b2a74a318efad89..906723104d553d2cb25465c4dfd488e213914a0f 100644 (file)
@@ -86,18 +86,6 @@ sub prepare_reindex ($$) {
        }
 }
 
-sub progress_prepare ($) {
-       my ($opt) = @_;
-       if ($opt->{quiet}) {
-               open my $null, '>', '/dev/null' or
-                       die "failed to open /dev/null: $!\n";
-               $opt->{1} = fileno($null);
-               $opt->{-dev_null} = $null;
-       } else {
-               $opt->{-progress} = sub { print STDERR @_ };
-       }
-}
-
 sub same_fs_or_die ($$) {
        my ($x, $y) = @_;
        return if ((stat($x))[0] == (stat($y))[0]); # 0 - st_dev
@@ -132,7 +120,7 @@ sub process_queue {
 sub run {
        my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact'
        my $cb = \&${\"PublicInbox::Xapcmd::$task"};
-       progress_prepare($opt ||= {});
+       PublicInbox::Admin::progress_prepare($opt ||= {});
        my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
        runnable_or_die($XAPIAN_COMPACT) if $opt->{compact};
        my $reindex; # v1:{ from => $x40 }, v2:{ from => [ $x40, $x40, .. ] } }
@@ -287,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) {