]> Sergey Matveev's repositories - public-inbox.git/commitdiff
search: require PublicInbox::Inbox ref here
authorEric Wong <e@80x24.org>
Fri, 14 Jun 2019 17:13:04 +0000 (17:13 +0000)
committerEric Wong <e@80x24.org>
Fri, 14 Jun 2019 17:27:10 +0000 (17:27 +0000)
No sense in supporting multiple methods of initialization
for an internal class.

lib/PublicInbox/Inbox.pm
lib/PublicInbox/Search.pm
t/altid.t
t/search.t

index c93303322194e024b8125b8d8b64ca014fe00483..10f716ca6d033b0aecaa7df8a37563997db7c368 100644 (file)
@@ -191,7 +191,7 @@ sub search ($;$) {
        my $srch = $self->{search} ||= eval {
                _cleanup_later($self);
                require PublicInbox::Search;
-               PublicInbox::Search->new($self, $self->{altid});
+               PublicInbox::Search->new($self);
        };
        ($over_only || eval { $srch->xdb }) ? $srch : undef;
 }
index 9903f427013bebeee9bbd1f427965a8c6cd84ede..098c97cdc2c11c72893d07a4eb4ffa3bb14bc856 100644 (file)
@@ -170,17 +170,12 @@ sub xdb ($) {
 }
 
 sub new {
-       my ($class, $mainrepo, $altid) = @_;
-       my $version = 1;
-       my $ibx = $mainrepo;
-       if (ref $ibx) {
-               $version = $ibx->{version} || 1;
-               $mainrepo = $ibx->{mainrepo};
-       }
+       my ($class, $ibx) = @_;
+       ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
        my $self = bless {
-               mainrepo => $mainrepo,
-               altid => $altid,
-               version => $version,
+               mainrepo => $ibx->{mainrepo},
+               altid => $ibx->{altid},
+               version => $ibx->{version} // 1,
        }, $class;
        my $dir = xdir($self, 1);
        $self->{over_ro} = PublicInbox::Over->new("$dir/over.sqlite3");
index 13a44a3b53221dcb1baacb63bd07dc0be69a823b..10bf8c659b25d1a85a6acc3f8f5664feb4b357c3 100644 (file)
--- a/t/altid.t
+++ b/t/altid.t
@@ -17,6 +17,7 @@ my $tmpdir = tempdir('pi-altid-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $git_dir = "$tmpdir/a.git";
 my $alt_file = "$tmpdir/another-nntp.sqlite3";
 my $altid = [ "serial:gmane:file=$alt_file" ];
+my $ibx;
 
 {
        my $mm = PublicInbox::Msgmap->new_file($alt_file, 1);
@@ -42,14 +43,14 @@ my $altid = [ "serial:gmane:file=$alt_file" ];
        $im->done;
 }
 {
-       my $ibx = PublicInbox::Inbox->new({mainrepo => $git_dir});
+       $ibx = PublicInbox::Inbox->new({mainrepo => $git_dir});
        $ibx->{altid} = $altid;
        my $rw = PublicInbox::SearchIdx->new($ibx, 1);
        $rw->index_sync;
 }
 
 {
-       my $ro = PublicInbox::Search->new($git_dir, $altid);
+       my $ro = PublicInbox::Search->new($ibx);
        my $msgs = $ro->query("gmane:1234");
        is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
 
index d4c1e150ef960ac0e581b48aafdf0f7ca8b96adb..a049c931c3910b048556f4af7c13d1f0e465ff23 100644 (file)
@@ -18,7 +18,7 @@ my $ibx = PublicInbox::Inbox->new({ mainrepo => $git_dir });
 my ($root_id, $last_id);
 
 is(0, system(qw(git init --shared -q --bare), $git_dir), "git init (main)");
-eval { PublicInbox::Search->new($git_dir)->xdb };
+eval { PublicInbox::Search->new($ibx)->xdb };
 ok($@, "exception raised on non-existent DB");
 
 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
@@ -27,7 +27,7 @@ $ibx->with_umask(sub {
        $rw->_xdb_release;
 });
 $rw = undef;
-my $ro = PublicInbox::Search->new($git_dir);
+my $ro = PublicInbox::Search->new($ibx);
 my $rw_commit = sub {
        $rw->commit_txn_lazy if $rw;
        $rw = PublicInbox::SearchIdx->new($ibx, 1);