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 1/6] inbox: add ->over method to ease access
Date: Wed, 15 May 2019 06:33:49 +0000	[thread overview]
Message-ID: <20190515063354.52259-2-e@80x24.org> (raw)
In-Reply-To: <20190515063354.52259-1-e@80x24.org>

One small step towards making installing Xapian optional for v2
and providing more WWW and NNTP functionality without it.
---
 lib/PublicInbox/Inbox.pm | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 286555f..e3bc104 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -168,12 +168,20 @@ sub mm {
 	};
 }
 
-sub search {
-	my ($self) = @_;
-	$self->{search} ||= eval {
+sub search ($;$) {
+	my ($self, $over_only) = @_;
+	my $srch = $self->{search} ||= eval {
 		_cleanup_later($self);
 		PublicInbox::Search->new($self, $self->{altid});
 	};
+	# TODO: lazily load Xapian
+	# return $srch if $over_only || eval { $srch->xdb };
+	# undef;
+}
+
+sub over ($) {
+	my $srch = search($_[0], 1) or return;
+	$srch->{over_ro};
 }
 
 sub try_cat {
@@ -280,7 +288,7 @@ sub nntp_url {
 
 sub nntp_usable {
 	my ($self) = @_;
-	my $ret = $self->mm && $self->search;
+	my $ret = mm($self) && over($self);
 	$self->{mm} = $self->{search} = undef;
 	$ret;
 }
@@ -322,30 +330,32 @@ sub mid2num($$) {
 
 sub smsg_by_mid ($$) {
 	my ($self, $mid) = @_;
-	my $srch = search($self) or return;
+	my $over = over($self) or return;
 	# favor the Message-ID we used for the NNTP article number:
 	defined(my $num = mid2num($self, $mid)) or return;
-	my $smsg = $srch->lookup_article($num) or return;
+	my $smsg = $over->get_art($num) or return;
 	PublicInbox::SearchMsg::psgi_cull($smsg);
 }
 
 sub msg_by_mid ($$;$) {
 	my ($self, $mid, $ref) = @_;
-	my $srch = search($self) or
+
+	over($self) or
 		return msg_by_path($self, mid2path($mid), $ref);
+
 	my $smsg = smsg_by_mid($self, $mid);
 	$smsg ? msg_by_smsg($self, $smsg, $ref) : undef;
 }
 
 sub recent {
 	my ($self, $opts, $after, $before) = @_;
-	search($self)->{over_ro}->recent($opts, $after, $before);
+	over($self)->recent($opts, $after, $before);
 }
 
 sub modified {
 	my ($self) = @_;
-	if (my $srch = search($self)) {
-		my $msgs = $srch->{over_ro}->recent({limit => 1});
+	if (my $over = over($self)) {
+		my $msgs = $over->recent({limit => 1});
 		if (my $smsg = $msgs->[0]) {
 			return $smsg->{ts};
 		}
-- 
EW


  reply	other threads:[~2019-05-15  6:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15  6:33 [PATCH 0/6] make Search::Xapian optional for v2, NNTP, etc Eric Wong
2019-05-15  6:33 ` Eric Wong [this message]
2019-05-15  6:33 ` [PATCH 2/6] nntp: use Inbox->over directly Eric Wong
2019-05-15  6:33 ` [PATCH 3/6] www: use Inbox->over where appropriate Eric Wong
2019-05-15  6:33 ` [PATCH 4/6] lazy load Xapian and make it optional for v2 Eric Wong
2019-05-15  6:33 ` [PATCH 5/6] searchidx: do not create empty Xapian partitions for basic Eric Wong
2019-05-15  6:33 ` [PATCH 6/6] admin: improve warnings and errors for missing modules Eric Wong
2019-05-22  0:35 ` [PATCH 0/6] make Search::Xapian optional for v2, NNTP, etc Eric Wong

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=20190515063354.52259-2-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).