From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20160620005717.1482-4-e@80x24.org> (raw)
In-Reply-To: <20160620005717.1482-1-e@80x24.org>
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 {
'<updated>' . strftime(DATEFMT, @t) . '</updated>';
}
-# 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(<pre\nstyle="white-space:pre-wrap">) .
- PublicInbox::View::multipart_text_as_html($mime, $href) .
- '</pre>';
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("<entry><author><name>$name</name><email>$email</email>" .
- "</author>$title$updated" .
- qq{<content\ntype="xhtml">} .
- qq{<div\nxmlns="http://www.w3.org/1999/xhtml">});
- $fh->write($content);
+ $s .= "<entry><author><name>$name</name><email>$email</email>" .
+ "</author>$title$updated" .
+ qq{<content\ntype="xhtml">} .
+ qq{<div\nxmlns="http://www.w3.org/1999/xhtml">} .
+ qq(<pre\nstyle="white-space:pre-wrap">) .
+ PublicInbox::View::multipart_text_as_html($mime, $href) .
+ '</pre>';
$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!</div></content><link\nhref="$href/"/>!.
- "<id>$id</id></entry>");
- 1;
+ $s .= qq!</div></content><link\nhref="$href/"/>!.
+ "<id>$id</id></entry>";
}
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);
}
next prev parent reply other threads:[~2016-06-20 0:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-20 0:57 [PATCH 0/7] www: various feed/streaming related cleanups Eric Wong
2016-06-20 0:57 ` [PATCH 1/7] MANIFEST: update with recent changes Eric Wong
2016-06-20 0:57 ` [PATCH 2/7] feed: avoid needless method dispatches on 404 Eric Wong
2016-06-20 0:57 ` Eric Wong [this message]
2016-06-20 0:57 ` [PATCH 4/7] mbox: remove feed dependency Eric Wong
2016-06-20 0:57 ` [PATCH 5/7] mbox: avoid write dependency for streaming Eric Wong
2016-06-20 0:57 ` [PATCH 6/7] feed: various object-orientation cleanups Eric Wong
2016-06-20 0:57 ` [PATCH 7/7] inbox: move field population logic to initializer Eric Wong
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=20160620005717.1482-4-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).