From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1879E1F61A for ; Sat, 10 Sep 2022 08:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662797932; bh=gXBEnWZTjNvtjR5rKw4UyH6+dStSGH5YMaqZHJBAkCY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i6DqBipkhHn+kL9VmdsO8GCZxksI/IjfHHgvTMp5BRrBnlkVcvoU/pofSkbf+Q87q t7Er53lEt2etk9VO2NixjQfg/GpM3AngolNwJwgnmZRUthwlPCmoDVpFsMB0Feg4gl 0K182YycoIcsMKP/PSn6cw2qevcRbZ71dgN59LLI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/38] view: rework single message page to compress earlier Date: Sat, 10 Sep 2022 08:16:54 +0000 Message-Id: <20220910081729.2011934-4-e@80x24.org> In-Reply-To: <20220910081729.2011934-1-e@80x24.org> References: <20220910081729.2011934-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can rely on deflate to compress large thread skeletons on single message pages. Subsequent commits will compress bodies, as well. --- lib/PublicInbox/View.pm | 42 ++++++++++++++++-------------------- lib/PublicInbox/WwwStream.pm | 14 ++++++++++-- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 446e6bb8..033af283 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -38,14 +38,12 @@ sub msg_page_i { : $ctx->gone('over'); $ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ? "../${\mid_href($smsg->{mid})}/" : ''; - my $obuf = _msg_page_prepare_obuf($eml, $ctx); - if (length($$obuf)) { + if (_msg_page_prepare_obuf($eml, $ctx)) { multipart_text_as_html($eml, $ctx); - $$obuf .= '
'; + ${$ctx->{obuf}} .= '
'; } - delete $ctx->{obuf}; - $$obuf .= html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg}; - $$obuf; + html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg}; + delete($ctx->{obuf}) // \''; } else { # called by WwwStream::async_next or getline $ctx->{smsg}; # may be undef } @@ -58,14 +56,12 @@ sub no_over_html ($) { my $eml = PublicInbox::Eml->new($bref); $ctx->{mhref} = ''; PublicInbox::WwwStream::init($ctx); - my $obuf = _msg_page_prepare_obuf($eml, $ctx); - if (length($$obuf)) { + if (_msg_page_prepare_obuf($eml, $ctx)) { # sets {-title_html} multipart_text_as_html($eml, $ctx); - $$obuf .= '
'; + ${$ctx->{obuf}} .= '
'; } - delete $ctx->{obuf}; - eval { $$obuf .= html_footer($ctx, $eml) }; - html_oneshot($ctx, 200, $$obuf); + html_footer($ctx, $eml); + $ctx->html_done(200); } # public functions: (unstable) @@ -669,7 +665,7 @@ sub _msg_page_prepare_obuf { if ($nr) { # unlikely if ($ctx->{chash} eq content_hash($eml)) { warn "W: BUG? @$mids not deduplicated properly\n"; - return \$rv; + return; } $rv .= "
WARNING: multiple messages have this Message-ID\n
";
@@ -746,7 +742,7 @@ sub _msg_page_prepare_obuf {
 	}
 	_parent_headers($ctx, $eml);
 	$rv .= "\n";
-	\$rv;
+	1;
 }
 
 sub SKEL_EXPAND () {
@@ -827,13 +823,11 @@ EOM
 	}
 }
 
-# returns a string buffer
+# appends to obuf
 sub html_footer {
 	my ($ctx, $hdr) = @_;
 	my $upfx = '../';
-	my $skel;
-	my $rv = '
';
-	my $related;
+	my ($related, $skel);
 	my $qry = delete $ctx->{-qry};
 	if ($qry && $ctx->{ibx}->isrch) {
 		my $q = ''; # search for either ancestor or descendent patches
@@ -896,15 +890,15 @@ EOF
 		} elsif ($u) { # unlikely
 			$parent = " parent";
 		}
-		$rv .= "$next $prev$parent ";
+		${$ctx->{obuf}} .= "
$next $prev$parent ";
 	} else { # unindexed inboxes w/o over
+		${$ctx->{obuf}} .= '
';
 		$skel = qq( latest);
 	}
-	$rv .= qq(reply);
-	$rv .= $skel;
-	$rv .= '
'; - $rv .= $related // ''; - $rv .= msg_reply($ctx, $hdr); + ${$ctx->{obuf}} .= qq(reply); + # $skel may be big for big threads, don't append it to obuf + $skel .= '
' . ($related // ''); + $ctx->zmore($skel .= msg_reply($ctx, $hdr)); # flushes obuf } sub linkify_ref_no_over { diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index f2777fdc..115e0440 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -27,6 +27,9 @@ sub init { my ($ctx, $cb) = @_; $ctx->{cb} = $cb; $ctx->{base_url} = base_url($ctx); + $ctx->{-res_hdr} = [ 'Content-Type' => 'text/html; charset=UTF-8' ]; + $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($ctx->{-res_hdr}, + $ctx->{env}); bless $ctx, __PACKAGE__; } @@ -164,6 +167,14 @@ sub getline { $ctx->zflush(_html_end($ctx)); } +sub html_done ($$) { + my ($ctx, $code) = @_; + my $bdy = $ctx->zflush(_html_end($ctx)); + my $res_hdr = delete $ctx->{-res_hdr}; + push @$res_hdr, 'Content-Length', length($bdy); + [ $code, $res_hdr, [ $bdy ] ] +} + sub html_oneshot ($$;@) { my ($ctx, $code) = @_[0, 1]; my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8', @@ -195,9 +206,8 @@ sub async_next ($) { sub aresponse { my ($ctx, $code, $cb) = @_; - my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ]; init($ctx, $cb); - $ctx->psgi_response($code, $res_hdr); + $ctx->psgi_response($code, delete $ctx->{-res_hdr}); } sub html_init {