From 11707dae97d1f4638157cfee298464b2f2deeed4 Mon Sep 17 00:00:00 2001 From: "Eric Wong (Contractor, The Linux Foundation)" Date: Thu, 29 Mar 2018 09:57:52 +0000 Subject: search: get rid of most lookup_* subroutines Too many similar functions doing the same basic thing was redundant and misleading, especially since Message-ID is no longer treated as a truly unique identifier. For displaying threads in the HTML, this makes it clear that we favor the primary Message-ID mapped to an NNTP article number if a message cannot be found. --- lib/PublicInbox/Search.pm | 56 +++++------------------------------------------ 1 file changed, 5 insertions(+), 51 deletions(-) (limited to 'lib/PublicInbox/Search.pm') diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 584a508e..7d42aaad 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -18,7 +18,7 @@ use constant YYYYMMDD => 5; # for searching in the WWW UI use Search::Xapian qw/:standard/; use PublicInbox::SearchMsg; use PublicInbox::MIME; -use PublicInbox::MID qw/mid_clean id_compress/; +use PublicInbox::MID qw/id_compress/; # This is English-only, everything else is non-standard and may be confused as # a prefix common in patch emails @@ -193,9 +193,8 @@ sub query { sub get_thread { my ($self, $mid, $opts) = @_; - my $smsg = retry_reopen($self, sub { lookup_skeleton($self, $mid) }); - - return { total => 0, msgs => [] } unless $smsg; + my $smsg = first_smsg_by_mid($self, $mid) or + return { total => 0, msgs => [] }; my $qtid = Search::Xapian::Query->new('G' . $smsg->thread_id); my $path = $smsg->path; if (defined $path && $path ne '') { @@ -346,48 +345,13 @@ sub query_ts { _do_enquire($self, $query, $opts); } -sub lookup_skeleton { +sub first_smsg_by_mid { my ($self, $mid) = @_; - my $skel = $self->{skel} or return lookup_message($self, $mid); - $mid = mid_clean($mid); - my $term = 'Q' . $mid; my $smsg; - my $beg = $skel->postlist_begin($term); - if ($beg != $skel->postlist_end($term)) { - my $doc_id = $beg->get_docid; - if (defined $doc_id) { - # raises on error: - my $doc = $skel->get_document($doc_id); - $smsg = PublicInbox::SearchMsg->wrap($doc, $mid); - $smsg->{doc_id} = $doc_id; - } - } + each_smsg_by_mid($self, $mid, sub { $smsg = $_[0]; undef }); $smsg; } -sub lookup_message { - my ($self, $mid) = @_; - $mid = mid_clean($mid); - - my $doc_id = $self->find_first_doc_id('Q' . $mid); - my $smsg; - if (defined $doc_id) { - # raises on error: - my $doc = $self->{xdb}->get_document($doc_id); - $smsg = PublicInbox::SearchMsg->wrap($doc, $mid); - $smsg->{doc_id} = $doc_id; - } - $smsg; -} - -sub lookup_mail { # no ghosts! - my ($self, $mid) = @_; - retry_reopen($self, sub { - my $smsg = lookup_skeleton($self, $mid) or return; - $smsg->load_expand; - }); -} - sub lookup_article { my ($self, $num) = @_; my $term = 'XNUM'.$num; @@ -447,16 +411,6 @@ sub find_doc_ids { ($db->postlist_begin($termval), $db->postlist_end($termval)); } -sub find_first_doc_id { - my ($self, $termval) = @_; - - my ($begin, $end) = $self->find_doc_ids($termval); - - return undef if $begin->equal($end); # not found - - $begin->get_docid; -} - # normalize subjects so they are suitable as pathnames for URLs # XXX: consider for removal sub subject_path { -- cgit v1.2.3-24-ge0c7