unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] searchview: use inbox->msg_by_mid
@ 2016-06-20 23:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-06-20 23:05 UTC (permalink / raw)
  To: meta

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 {

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-20 23:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-20 23:05 [PATCH] searchview: use inbox->msg_by_mid Eric Wong

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).