From: Eric Wong Date: Tue, 26 Aug 2025 19:50:45 +0000 (+0000) Subject: searchidx: take Getopt::Long options hashref on create X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d0b933bd4b7e205534264836ddc314758b7577ae;p=thirdparty%2Fpublic-inbox.git searchidx: take Getopt::Long options hashref on create 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. --- diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index f1aec53d2..3c3d9f08b 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -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 diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index a4e63a5c4..e64848e3d 100644 --- a/lib/PublicInbox/InboxWritable.pm +++ b/lib/PublicInbox/InboxWritable.pm @@ -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); diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 1b8f0f612..e2fe19c79 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -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; } diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 4a8a184e2..17cf2efa8 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -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'; diff --git a/t/altid.t b/t/altid.t index 2692029e1..b09236d50 100644 --- a/t/altid.t +++ b/t/altid.t @@ -1,5 +1,5 @@ #!perl -w -# Copyright (C) 2016-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ 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; } { diff --git a/t/inbox_idle.t b/t/inbox_idle.t index 94f3845c4..d24553302 100644 --- a/t/inbox_idle.t +++ b/t/inbox_idle.t @@ -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 diff --git a/t/psgi_mount.t b/t/psgi_mount.t index 7117cda30..48466cffa 100644 --- a/t/psgi_mount.t +++ b/t/psgi_mount.t @@ -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')); diff --git a/t/psgi_search.t b/t/psgi_search.t index 8d47356e7..6d2aa8a6b 100644 --- a/t/psgi_search.t +++ b/t/psgi_search.t @@ -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; diff --git a/t/search-thr-index.t b/t/search-thr-index.t index aecd064fb..ab6d3bbbf 100644 --- a/t/search-thr-index.t +++ b/t/search-thr-index.t @@ -1,5 +1,5 @@ #!perl -w -# Copyright (C) 2017-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ 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] diff --git a/t/search.t b/t/search.t index 0c6aace80..6be48ead2 100644 --- a/t/search.t +++ b/t/search.t @@ -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; diff --git a/t/v1-add-remove-add.t b/t/v1-add-remove-add.t index 50ff81435..57c7bdb51 100644 --- a/t/v1-add-remove-add.t +++ b/t/v1-add-remove-add.t @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ 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'); diff --git a/t/v1reindex.t b/t/v1reindex.t index 2d12e3f5d..5c00ca919 100644 --- a/t/v1reindex.t +++ b/t/v1reindex.t @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ 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 }); diff --git a/xt/mem-nntpd-tls.t b/xt/mem-nntpd-tls.t index ec639a8bf..a9e494017 100644 --- a/xt/mem-nntpd-tls.t +++ b/xt/mem-nntpd-tls.t @@ -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; } }