From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DE5FC1F4B3; Sun, 13 Sep 2015 23:19:40 +0000 (UTC) Date: Sun, 13 Sep 2015 23:19:40 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [REJECT 4/3] searchview: implement flat view for full message Message-ID: <20150913231940.GA2161@dcvr.yhbt.net> References: <20150913223547.5083-1-e@80x24.org> <20150913223751.GA22152@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150913223751.GA22152@dcvr.yhbt.net> List-Id: Rejecting this, as it's too much clutter and options. People who really want a flat view should use the Atom feed. --- lib/PublicInbox/SearchView.pm | 109 ++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index b65351a..f0c6670 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -44,7 +44,10 @@ sub sres_top_html { $res .= search_nav_top($mset, $q); if ($x eq 't') { return sub { tdump($_[0], $res, $mset, $q, $ctx) }; + } elsif ($x eq 'f') { + return sub { fdump($_[0], $res, $mset, $q, $ctx) }; } + $res .= "\n\n"; dump_mset(\$res, $mset); $res .= search_nav_bot($mset, $q) . "\n\n" . foot($ctx); @@ -96,17 +99,24 @@ sub search_nav_top { $rv .= qq{date|relevance}; } - $rv .= '] view['; + $rv .= '] view: ['; my $x = $q->{x}; + my $t = $q->qs_html(x => 't'); + my $s = $q->qs_html(x => ''); + my $f = $q->qs_html(x => 'f'); if ($x eq '') { - my $t = $q->qs_html(x => 't'); - $rv .= qq{summary|}; - $rv .= qq{threaded} - } elsif ($q->{x} eq 't') { - my $s = $q->qs_html(x => ''); - $rv .= qq{summary|}; - $rv .= qq{threaded}; + $rv .= qq{short|} . + qq{threaded|} . + qq{flat}; + } elsif ($x eq 't') { + $rv .= qq{short|} . + qq{threaded|} . + qq{flat}; + } elsif ($x eq 'f') { + $rv .= qq{short|} . + qq{threaded|} . + qq{flat}; } my $A = $q->qs_html(x => 'A'); $rv .= qq{|Atom}; @@ -136,8 +146,8 @@ sub search_nav_bot { $rv; } -sub tdump { - my ($cb, $res, $mset, $q, $ctx) = @_; +sub dump_prepare { + my ($cb, $res, $mset, $ctx) = @_; my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]); $fh->write($res); my %pct; @@ -148,56 +158,81 @@ sub tdump { $m = $m->mini_mime; $m; } ($mset->items); + my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct }; + $ctx->{searchview} = 1; + require PublicInbox::GitCatFile; + my $git = PublicInbox::GitCatFile->new($ctx->{git_dir}); + $state->{git} = $git; + + ($fh, \@m, $git, $state); +} + +sub dump_end { + my ($fh, $mset, $q, $ctx) = @_; + Email::Address->purge_cache; + + $fh->write(search_nav_bot($mset, $q). "\n\n" . + foot($ctx). ''); + $fh->close; +} + +sub fdump { + my ($cb, $res, $mset, $q, $ctx) = @_; + my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx); + mime_dump($fh, $git, $_, 0, $state) for (@$m); + dump_end($fh, $mset, $q, $ctx); +} + +sub do_thread { + my ($m, $pct, $q) = @_; require PublicInbox::Thread; - my $th = PublicInbox::Thread->new(@m); + my $th = PublicInbox::Thread->new(@$m); { no warnings 'once'; $Mail::Thread::nosubject = 0; + $th->thread; } - $th->thread; if ($q->{r}) { $th->order(sub { - sort { (eval { $pct{$b->topmost->messageid} } || 0) + sort { (eval { $pct->{$b->topmost->messageid} } || 0) <=> - (eval { $pct{$a->topmost->messageid} } || 0) + (eval { $pct->{$a->topmost->messageid} } || 0) } @_; }); } else { no warnings 'once'; $th->order(*PublicInbox::View::rsort_ts); } + $th; +} - require PublicInbox::GitCatFile; - my $git = PublicInbox::GitCatFile->new($ctx->{git_dir}); - my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct }; - $ctx->{searchview} = 1; +sub tdump { + my ($cb, $res, $mset, $q, $ctx) = @_; + my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx); + my $th = do_thread($m, $state->{pct}, $q); tdump_ent($fh, $git, $state, $_, 0) for $th->rootset; - $git = undef; - Email::Address->purge_cache; + dump_end($fh, $mset, $q, $ctx); +} - $fh->write(search_nav_bot($mset, $q). "\n\n" . - foot($ctx). ''); +sub mime_dump { + my ($fh, $git, $mime, $level, $state) = @_; - $fh->close; + # lazy load the full message from mini_mime: + my $mid = $mime->header('Message-ID'); + $mime = eval { + my $path = mid2path(mid_clean($mid)); + Email::MIME->new($git->cat_file('HEAD:'.$path)); + }; + PublicInbox::View::index_entry($fh, $mime, $level, $state) if $mime; + $mime; } sub tdump_ent { my ($fh, $git, $state, $node, $level) = @_; return unless $node; - my $mime = $node->message; - - if ($mime) { - # lazy load the full message from mini_mime: - my $mid = $mime->header('Message-ID'); - $mime = eval { - my $path = mid2path(mid_clean($mid)); - Email::MIME->new($git->cat_file('HEAD:'.$path)); - }; - } - if ($mime) { - PublicInbox::View::index_entry($fh, $mime, $level, $state); - } else { + + unless (mime_dump($fh, $git, $node->message, $level, $state)) { my $mid = $node->messageid; $fh->write(PublicInbox::View::ghost_table('', $mid, $level)); } @@ -295,7 +330,7 @@ sub qs_html { $qs .= "&r"; } if (my $x = $self->{x}) { - $qs .= "&x=$x" if ($x eq 't' || $x eq 'A'); + $qs .= "&x=$x" if ($x =~ /\A(?:A|t|f)\z/); } $qs; } -- EW