]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
searchidx: take Getopt::Long options hashref on create
authorEric Wong <e@80x24.org>
Tue, 26 Aug 2025 19:50:45 +0000 (19:50 +0000)
committerEric Wong <e@80x24.org>
Thu, 28 Aug 2025 18:48:16 +0000 (18:48 +0000)
Relying more on the hashref populated by Getopt::Long should
reduce cognitive overhead.  Future commits will allow us to
eliminate the {-no_fsync} and {-dangerous} fields and allow
us to more easily support new switches for toggling CoW/No_COW,
and other options for SQLite and Xapian tuning.

13 files changed:
lib/PublicInbox/Admin.pm
lib/PublicInbox/InboxWritable.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm
t/altid.t
t/inbox_idle.t
t/psgi_mount.t
t/psgi_search.t
t/search-thr-index.t
t/search.t
t/v1-add-remove-add.t
t/v1reindex.t
xt/mem-nntpd-tls.t

index f1aec53d2e99d15d215567046ffb1eb1f1815e56..3c3d9f08b445b4d46be3cf477bef127fed2d1039 100644 (file)
@@ -309,7 +309,7 @@ EOM
                $idx = $v2w;
        } else {
                require PublicInbox::SearchIdx;
-               $idx = PublicInbox::SearchIdx->new($ibx, 1);
+               $idx = PublicInbox::SearchIdx->new($ibx, $opt);
        }
        $idx->index_sync($opt);
        $idx->{nidx} // 0; # returns number processed
index a4e63a5c4a921b70c8d8fce277ff561adb57224c..e64848e3d561e93494cb5a1c5777241d33242080 100644 (file)
@@ -36,7 +36,7 @@ sub _init_v1 {
                        $opt->{wal}) {
                require PublicInbox::SearchIdx;
                require PublicInbox::Msgmap;
-               my $sidx = PublicInbox::SearchIdx->new($self, 1); # just create
+               my $sidx = PublicInbox::SearchIdx->new($self, $opt);
                $sidx->{oidx}->{journal_mode} = 'wal' if $opt->{wal};
                $sidx->begin_txn_lazy;
                my $mm = PublicInbox::Msgmap->new_file($self, 1, $opt);
index 1b8f0f612c261afb24394f5c2945bc9b3d141b98..e2fe19c79c0d6f53c5c84dfb93b64b8dfcac0a57 100644 (file)
@@ -55,7 +55,7 @@ our $INDEXLEVELS = qr/\A(?:full|medium|basic)\z/;
 our $PATCHID_BROKEN;
 
 sub new {
-       my ($class, $ibx, $creat, $shard) = @_;
+       my ($class, $ibx, $creat_opt, $shard) = @_;
        ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
        my $inboxdir = $ibx->{inboxdir};
        my $version = $ibx->version;
@@ -92,7 +92,7 @@ sub new {
        } else {
                die "unsupported inbox version=$version\n";
        }
-       $self->{creat} = ($creat || 0) == 1;
+       $self->{creat} = !!$creat_opt;
        $self;
 }
 
index 4a8a184e21c14f3755479b771362886157816686..17cf2efa8f6e4b052468bdd03b315208baf69f14 100644 (file)
@@ -1325,7 +1325,7 @@ sub index_sync {
        if (!$self->{quit} && $opt->{reindex} &&
                        !ref($opt->{reindex}) && $idxlevel ne 'basic') {
                $self->lock_acquire;
-               my $s0 = PublicInbox::SearchIdx->new($self->{ibx}, 0, 0);
+               my $s0 = PublicInbox::SearchIdx->new($self->{ibx}, $opt, 0);
                if (my $xdb = $s0->idx_acquire) {
                        my $n = $xdb->get_metadata('has_threadid');
                        $xdb->set_metadata('has_threadid', '1') if $n ne '1';
index 2692029e1085248878c6d1bed53eb560dfcfbe80..b09236d50edadb32b402a67ea9d3839ac9551d50 100644 (file)
--- a/t/altid.t
+++ b/t/altid.t
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
@@ -34,7 +34,7 @@ hello world gmane:666
 EOF
        };
        $ibx->{altid} = $altid;
-       PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
+       PublicInbox::SearchIdx->new($ibx, { wal => 1 })->index_sync;
 }
 
 {
index 94f3845c416c4deb8030bd5f6f58602afcb33f88..d2455330204ef17572d0a4e097026391c98bd84c 100644 (file)
@@ -23,7 +23,7 @@ for my $V (1, 2) {
                $ibx->init_inbox(0);
                $_[0] = undef;
                return if $V != 1;
-               my $sidx = PublicInbox::SearchIdx->new($ibx, 1);
+               my $sidx = PublicInbox::SearchIdx->new($ibx, { wal => 1 });
                $sidx->idx_acquire;
                $sidx->set_metadata_once;
                $sidx->idx_release; # allow watching on lockfile
index 7117cda3090e1355f0b44b5c11e903ca7e074ba1..48466cffa95e7da6b99a2dbf2ffe6559a1855139 100644 (file)
@@ -66,7 +66,7 @@ test_psgi($app, sub {
 SKIP: {
        require_mods(qw(DBD::SQLite Xapian IO::Uncompress::Gunzip), 3);
        require_ok 'PublicInbox::SearchIdx';
-       PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
+       PublicInbox::SearchIdx->new($ibx, { wal => 1 })->index_sync;
        test_psgi($app, sub {
                my ($cb) = @_;
                my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
index 8d47356e7427312a3360c60d05344be170e35982..6d2aa8a6b30a9bd933cba06961f8145aa8f80714 100644 (file)
@@ -148,7 +148,7 @@ test_psgi(sub { $www->call(@_) }, sub {
 
        # clobber has_threadid to emulate old versions:
        {
-               my $sidx = PublicInbox::SearchIdx->new($ibx, 0);
+               my $sidx = PublicInbox::SearchIdx->new($ibx);
                my $xdb = $sidx->idx_acquire;
                $xdb->set_metadata('has_threadid', '0');
                $sidx->idx_release;
index aecd064fb79c75083433cebbed8a1783a88313e9..ab6d3bbbfb4e139f4b0342eb7af9ecdead3e4678 100644 (file)
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
@@ -17,7 +17,7 @@ my $git_dir = "$tmpdir/a.git";
 
 PublicInbox::Import::init_bare($git_dir);
 my $ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
-my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+my $rw = PublicInbox::SearchIdx->new($ibx, { wal => 1 });
 ok($rw, "search indexer created");
 my $data = <<'EOF';
 Subject: [RFC 00/14]
index 0c6aace80362840377e30c26a62cdead2431bc5e..6be48ead248322e2a21168069b99cc780dd61f10 100644 (file)
@@ -23,7 +23,8 @@ is(0, xsys(qw(git init --shared -q --bare), $git_dir), "git init (main)")
 eval { PublicInbox::Search->new($ibx)->xdb };
 ok($@, "exception raised on non-existent DB");
 
-my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+my $sidx_opt = { wal => 1 };
+my $rw = PublicInbox::SearchIdx->new($ibx, $sidx_opt);
 $ibx->with_umask(sub {
        $rw->idx_acquire;
        $rw->idx_release;
@@ -31,7 +32,7 @@ $ibx->with_umask(sub {
 $rw = undef;
 my $rw_commit = sub {
        $rw->commit_txn_lazy if $rw;
-       $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       $rw = PublicInbox::SearchIdx->new($ibx, $sidx_opt);
        $rw->{qp_flags} = 0; # quiet a warning
        $rw->begin_txn_lazy;
        $ibx->search->reopen;
index 50ff81435f5904059ad8f4eacaeeb6d9dfb32114..57c7bdb519f30fa2a1a7b823f0f4537bb6597714 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -30,7 +30,7 @@ ok($im->add($mime), 'message added');
 ok($im->remove($mime), 'message removed');
 ok($im->add($mime), 'message added again');
 $im->done;
-my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+my $rw = PublicInbox::SearchIdx->new($ibx, { wal => 1 });
 $rw->index_sync;
 my $msgs = $ibx->over->recent({limit => 10});
 is($msgs->[0]->{mid}, 'a-mid@b', 'message exists in history');
index 2d12e3f5dde22caf1e7110871cd9d7f3e9531a09..5c00ca91935c3f544e765a288024e4f532d09435 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -31,6 +31,8 @@ EOF
 my $minmax;
 my $msgmap;
 my ($mark1, $mark2, $mark3, $mark4);
+my $sidx_opt = { wal => 1 };
+my $search_idx_new = sub { PublicInbox::SearchIdx->new($_[0], $sidx_opt) };
 {
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
@@ -54,7 +56,7 @@ my ($mark1, $mark2, $mark3, $mark4);
        }
 
        $im->done;
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync() };
        is($@, '', 'no error from indexing');
 
@@ -81,7 +83,7 @@ my ($mark1, $mark2, $mark3, $mark4);
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing');
        $im->done;
@@ -99,7 +101,7 @@ ok(!-d $xap, 'Xapian directories removed');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
 
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing');
@@ -123,7 +125,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing without msgmap');
        is(scalar(@warn), 0, 'no warnings from reindexing');
@@ -146,7 +148,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing without msgmap');
        is_deeply(\@warn, [], 'no warnings');
@@ -170,7 +172,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        $config{indexlevel} = 'medium';
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing without msgmap');
        is_deeply(\@warn, [], 'no warnings');
@@ -196,7 +198,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        $config{indexlevel} = 'basic';
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing without msgmap');
        is_deeply(\@warn, [], 'no warnings');
@@ -221,7 +223,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        $config{indexlevel} = 'medium';
        my $ibx = PublicInbox::Inbox->new(\%config);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        eval { $rw->index_sync({reindex => 1}) };
        is($@, '', 'no error from indexing');
        is_deeply(\@warn, [], 'no warnings');
@@ -244,7 +246,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark1 4 simple additions in the same index_sync
        eval { $rw->index_sync({ref => $mark1}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -268,7 +270,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark2 A delete separated form and add in the same index_sync
        eval { $rw->index_sync({ref => $mark2}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -291,7 +293,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark3 adds following the delete at mark2
        eval { $rw->index_sync({ref => $mark3}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -320,7 +322,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark4 A delete of an older message
        eval { $rw->index_sync({ref => $mark4}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -354,7 +356,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark2 an add and it's delete in the same index_sync
        eval { $rw->index_sync({ref => $mark2}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -377,7 +379,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark3 adds following the delete at mark2
        eval { $rw->index_sync({ref => $mark3}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -406,7 +408,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        # mark4 A delete of an older message
        eval { $rw->index_sync({ref => $mark4}) };
        is($@, '', 'no error from reindexing without msgmap');
@@ -447,7 +449,7 @@ SELECT tid FROM over WHERE num > 0 ORDER BY tid ASC
        my $tid = PublicInbox::OverIdx::get_counter($dbh, 'thread');
        my $nr = $dbh->do('UPDATE over SET tid = ?', undef, $tid);
 
-       my $rw = PublicInbox::SearchIdx->new($ibx, 1);
+       my $rw = $search_idx_new->($ibx);
        my @pr;
        my $pr = sub { push @pr, @_ };
        $rw->index_sync({reindex => 1, rethread => 1, -progress => $pr });
index ec639a8bff85a53e2cb1c56ca902e737947a847e..a9e49401758871cd451bbeab2eafc6290084cfff 100644 (file)
@@ -57,7 +57,7 @@ EOF
        ok($im->add($eml), 'message added');
        $im->done;
        if ($version == 1) {
-               my $s = PublicInbox::SearchIdx->new($ibx, 1);
+               my $s = PublicInbox::SearchIdx->new($ibx, { wal => 1 });
                $s->index_sync;
        }
 }