From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8A0772018E for ; Mon, 20 Jun 2016 00:57:19 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/7] feed: remove dependence on fh->write for streaming Date: Mon, 20 Jun 2016 00:57:13 +0000 Message-Id: <20160620005717.1482-4-e@80x24.org> In-Reply-To: <20160620005717.1482-1-e@80x24.org> References: <20160620005717.1482-1-e@80x24.org> List-Id: We'll be switching to a getline/close response body to give the HTTP server more control when dealing with slow clients. --- lib/PublicInbox/Feed.pm | 44 ++++++++++++++++++++++--------------------- lib/PublicInbox/SearchView.pm | 3 ++- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index d88421b..07dce9e 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -72,7 +72,9 @@ sub emit_atom { $fh->write($x . feed_updated(undef, $ts)); $x = undef; } - add_to_feed($feed_opts, $fh, $path, $git); + my $s = feed_entry($feed_opts, $path, $git) or return 0; + $fh->write($s); + 1; }); end_feed($fh); } @@ -103,7 +105,8 @@ sub emit_atom_thread { my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); foreach my $msg (@{$res->{msgs}}) { - add_to_feed($feed_opts, $fh, mid2path($msg->mid), $git); + my $s = feed_entry($feed_opts, mid2path($msg->mid), $git); + $fh->write($s) if defined $s; } end_feed($fh); } @@ -306,52 +309,51 @@ sub feed_updated { '' . strftime(DATEFMT, @t) . ''; } -# returns 0 (skipped) or 1 (added) -sub add_to_feed { - my ($feed_opts, $fh, $add, $git) = @_; +# returns undef or string +sub feed_entry { + my ($feed_opts, $add, $git) = @_; - my $mime = do_cat_mail($git, $add) or return 0; + my $mime = do_cat_mail($git, $add) or return; my $url = $feed_opts->{url}; my $midurl = $feed_opts->{midurl}; my $header_obj = $mime->header_obj; my $mid = $header_obj->header_raw('Message-ID'); - defined $mid or return 0; + defined $mid or return; $mid = PublicInbox::Hval->new_msgid($mid); my $href = $midurl.$mid->as_href; - my $content = qq() . - PublicInbox::View::multipart_text_as_html($mime, $href) . - ''; my $date = $header_obj->header('Date'); my $updated = feed_updated($date); my $title = $header_obj->header('Subject'); - defined $title or return 0; + defined $title or return; $title = title_tag($title); - my $from = $header_obj->header('From') or return 0; + my $from = $header_obj->header('From') or return; my ($email) = PublicInbox::Address::emails($from); my $name = PublicInbox::Address::from_name($from); $name = ascii_html($name); $email = ascii_html($email); + my $s = ''; if (delete $feed_opts->{emit_header}) { - $fh->write(atom_header($feed_opts, $title) . $updated); + $s .= atom_header($feed_opts, $title) . $updated; } - $fh->write("$name$email" . - "$title$updated" . - qq{} . - qq{}); - $fh->write($content); + $s .= "$name$email" . + "$title$updated" . + qq{} . + qq{} . + qq() . + PublicInbox::View::multipart_text_as_html($mime, $href) . + ''; $add =~ tr!/!!d; my $h = '[a-f0-9]'; my (@uuid5) = ($add =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o); my $id = 'urn:uuid:' . join('-', @uuid5); - $fh->write(qq!!. - "$id"); - 1; + $s .= qq!!. + "$id"; } sub do_cat_mail { diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 2ec7ddf..d4c44ba 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -249,7 +249,8 @@ sub adump { for ($mset->items) { $x = PublicInbox::SearchMsg->load_doc($_->get_document)->mid; $x = mid2path($x); - PublicInbox::Feed::add_to_feed($feed_opts, $fh, $x, $git); + my $s = PublicInbox::Feed::feed_entry($feed_opts, $x, $git); + $fh->write($s) if defined $s; } PublicInbox::Feed::end_feed($fh); }