about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-15 01:18:05 +0000
committerEric Wong <e@80x24.org>2019-05-15 01:18:47 +0000
commita796afa762b6e204f611a69833064bf3656d1a62 (patch)
tree61b5d968ad1d75ca9013a4f141c6754ac3be9eaa /lib
parent2d51a2accd28465c915f91ab48c7e52a81d87a68 (diff)
downloadpublic-inbox-a796afa762b6e204f611a69833064bf3656d1a62.tar.gz
inbox: add ->over method to ease access
One small step towards making installing Xapian optional for v2
and providing more WWW and NNTP functionality without it.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Inbox.pm30
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 286555f6..e3bc1048 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};
                 }