unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] searchview: use inbox->msg_by_mid
Date: Mon, 20 Jun 2016 23:05:02 +0000	[thread overview]
Message-ID: <20160620230502.32241-1-e@80x24.org> (raw)

This abstracts out the path lookup logic and and allow us
potentially allow different heads in the same repository.

We may also bypass slow tree name lookups in the future
by storing the raw blob ID in the Xapian document.

Followup-to: 4b313dc74bc9 ("feed: various object-orientation cleanups")
---
 lib/PublicInbox/SearchView.pm | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 7f8f4af..6f67a37 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -8,7 +8,7 @@ use warnings;
 use PublicInbox::SearchMsg;
 use PublicInbox::Hval qw/ascii_html/;
 use PublicInbox::View;
-use PublicInbox::MID qw(mid2path mid_clean mid_mime);
+use PublicInbox::MID qw(mid2path mid_mime);
 use Email::MIME;
 require PublicInbox::Git;
 require PublicInbox::Thread;
@@ -165,16 +165,16 @@ sub tdump {
 		$th->order(*PublicInbox::View::sort_ts);
 	}
 	@rootset = $th->rootset;
-	my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
 	my $state = {
 		ctx => $ctx,
 		anchor_idx => 0,
 		pct => \%pct,
 		cur_level => 0,
+		-inbox => $ctx->{-inbox},
 		fh => $fh,
 	};
 	$ctx->{searchview} = 1;
-	tdump_ent($git, $state, $_, 0) for @rootset;
+	tdump_ent($state, $_, 0) for @rootset;
 	PublicInbox::View::thread_adj_level($state, 0);
 
 	$fh->write(search_nav_bot($mset, $q). "\n\n" .
@@ -184,17 +184,15 @@ sub tdump {
 }
 
 sub tdump_ent {
-	my ($git, $state, $node, $level) = @_;
+	my ($state, $node, $level) = @_;
 	return unless $node;
 	my $mime = $node->message;
 
 	if ($mime) {
 		# lazy load the full message from mini_mime:
 		my $mid = mid_mime($mime);
-		$mime = eval {
-			my $path = mid2path(mid_clean($mid));
-			Email::MIME->new($git->cat_file('HEAD:'.$path));
-		};
+		$mime = eval { $state->{-inbox}->msg_by_mid($mid) } and
+			$mime = Email::MIME->new($mime);
 	}
 	if ($mime) {
 		my $end = PublicInbox::View::thread_adj_level($state, $level);
@@ -204,8 +202,8 @@ sub tdump_ent {
 		my $mid = $node->messageid;
 		PublicInbox::View::ghost_flush($state, '', $mid, $level);
 	}
-	tdump_ent($git, $state, $node->child, $level + 1);
-	tdump_ent($git, $state, $node->next, $level);
+	tdump_ent($state, $node->child, $level + 1);
+	tdump_ent($state, $node->next, $level);
 }
 
 sub foot {

                 reply	other threads:[~2016-06-20 23:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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: https://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=20160620230502.32241-1-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.
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).