user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] search: require PublicInbox::Inbox ref here
Date: Fri, 14 Jun 2019 17:17:25 +0000	[thread overview]
Message-ID: <20190614171725.12820-3-e@80x24.org> (raw)
In-Reply-To: <20190614171725.12820-1-e@80x24.org>

No sense in supporting multiple methods of initialization
for an internal class.
---
 lib/PublicInbox/Inbox.pm  |  2 +-
 lib/PublicInbox/Search.pm | 15 +++++----------
 t/altid.t                 |  5 +++--
 t/search.t                |  4 ++--
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index c933033..10f716c 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -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;
 }
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 9903f42..098c97c 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -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");
diff --git a/t/altid.t b/t/altid.t
index 13a44a3..10bf8c6 100644
--- 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');
 
diff --git a/t/search.t b/t/search.t
index d4c1e15..a049c93 100644
--- a/t/search.t
+++ b/t/search.t
@@ -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);
-- 
EW


      parent reply	other threads:[~2019-06-14 17:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 17:17 [PATCH 0/2] search*: require Inbox refs for ->new Eric Wong
2019-06-14 17:17 ` [PATCH 1/2] searchidx: require PublicInbox::Inbox (or InboxWritable) ref Eric Wong
2019-06-14 17:17 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190614171725.12820-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).