about summary refs log tree commit homepage
path: root/lib/PublicInbox/Feed.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-22 00:06:45 +0000
committerEric Wong <e@80x24.org>2015-08-22 01:57:35 +0000
commit1704bdb4aabdbc155eb962edf51498f59b65c839 (patch)
tree6f88e2d1662a99062b0ebd74d94f7bd7c0db56e6 /lib/PublicInbox/Feed.pm
parent62395935e7bdd8e67776ebb9018f4633e67ff081 (diff)
downloadpublic-inbox-1704bdb4aabdbc155eb962edf51498f59b65c839.tar.gz
This should allow progressive rendering on the client and reduce
memory usage on the server.  Unfortunately XML::Atom::SimpleFeed
does not yet support streaming, so we may not use it in the
future.
Diffstat (limited to 'lib/PublicInbox/Feed.pm')
-rw-r--r--lib/PublicInbox/Feed.pm43
1 files changed, 25 insertions, 18 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 40f08ac7..5d122ac6 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -52,7 +52,15 @@ sub generate {
 }
 
 sub generate_html_index {
-        my ($class, $ctx) = @_;
+        my ($ctx) = @_;
+        sub { emit_html_index($_[0], $ctx) };
+}
+
+# private subs
+
+sub emit_html_index {
+        my ($cb, $ctx) = @_;
+        my $fh = $cb->([200,['Content-Type'=>'text/html; charset=UTF-8']]);
 
         my $max = $ctx->{max} || MAX_PER_PAGE;
         my $feed_opts = get_feedopts($ctx);
@@ -61,11 +69,11 @@ sub generate_html_index {
         $title = PublicInbox::Hval->new_oneline($title)->as_html;
         my $atom_url = $feed_opts->{atomurl};
 
-        my $html = "<html><head><title>$title</title>" .
-                "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
-                "href=\"$atom_url\"\ntype=\"application/atom+xml\"/>" .
-                '</head><body>' . PublicInbox::View::PRE_WRAP .
-                "<b>$title</b> (<a\nhref=\"$atom_url\">Atom feed</a>)\n";
+        $fh->write("<html><head><title>$title</title>" .
+                   "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
+                   "href=\"$atom_url\"\ntype=\"application/atom+xml\"/>" .
+                   '</head><body>' . PublicInbox::View::PRE_WRAP .
+                   "<b>$title</b> (<a\nhref=\"$atom_url\">Atom feed</a>)\n");
 
         my $state;
         my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
@@ -80,8 +88,7 @@ sub generate_html_index {
                         add_topic($git, $srch, $topics, $path, $ts, $u, $subj);
                 } else {
                         my $mime = do_cat_mail($git, $path) or return 0;
-                        $html .=
-                             PublicInbox::View->index_entry($mime, 0, $state);
+                        PublicInbox::View::index_entry($fh, $mime, 0, $state);
                         1;
                 }
         });
@@ -94,12 +101,11 @@ sub generate_html_index {
                 $footer .= "\n" . $list_footer if $list_footer;
                 $footer = "<hr /><pre>$footer</pre>";
         }
-        dump_topics(\$html, $topics) if $topics;
-        $html .= "$footer</body></html>";
+        $fh->write(dump_topics($topics)) if $topics;
+        $fh->write("$footer</body></html>");
+        $fh->close;
 }
 
-# private subs
-
 sub nav_footer {
         my ($cgi, $last, $feed_opts, $state) = @_;
         $cgi or return '';
@@ -328,27 +334,28 @@ sub add_topic {
 }
 
 sub dump_topics {
-        my ($dst, $topics) = @_;
+        my ($topics) = @_;
         my ($order, $subjs) = @$topics;
-        $$dst .= "\n[No recent topics]" unless (scalar @$order);
+        my $dst = '';
+        $dst .= "\n[No recent topics]" unless (scalar @$order);
         while (defined(my $info = shift @$order)) {
                 my ($mid, $ts, $u, $subj) = @$info;
                 my $n = delete $subjs->{$subj};
                 $mid = PublicInbox::Hval->new($mid)->as_href;
                 $subj = PublicInbox::Hval->new($subj)->as_html;
                 $u = PublicInbox::Hval->new($u)->as_html;
-                $$dst .= "\n<a\nhref=\"t/$mid.html#u\"><b>$subj</b></a>\n- ";
+                $dst .= "\n<a\nhref=\"t/$mid.html#u\"><b>$subj</b></a>\n- ";
                 $ts = POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
                 if ($n == 1) {
-                        $$dst .= "created by $u @ $ts UTC\n"
+                        $dst .= "created by $u @ $ts UTC\n"
                 } else {
                         # $n isn't the total number of posts on the topic,
                         # just the number of posts in the current "git log"
                         # window, so leave it unlabeled
-                        $$dst .= "updated by $u @ $ts UTC ($n)\n"
+                        $dst .= "updated by $u @ $ts UTC ($n)\n"
                 }
         }
-        $$dst .= '</pre>'
+        $dst .= '</pre>'
 }
 
 1;