user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 01/11] feed: remove threading from index
Date: Thu, 20 Aug 2015 02:57:13 +0000	[thread overview]
Message-ID: <1440039443-27052-1-git-send-email-e@80x24.org> (raw)

We'll be making the index smarter for people with search
support enabled.  Otherwise, it'll be chronological and
a bit dumb.  At least it'll use less memory.
---
 lib/PublicInbox/Feed.pm | 72 ++++++++++++++++---------------------------------
 1 file changed, 23 insertions(+), 49 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 95bde4f..253eed2 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -40,7 +40,7 @@ sub generate {
 
 	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
 	each_recent_blob($ctx, sub {
-		my ($add) = @_;
+		my ($add, undef) = @_;
 		add_to_feed($feed_opts, $feed, $add, $git);
 	});
 	$git = undef; # destroy pipes
@@ -50,7 +50,6 @@ sub generate {
 
 sub generate_html_index {
 	my ($class, $ctx) = @_;
-	require PublicInbox::Thread;
 
 	my $max = $ctx->{max} || MAX_PER_PAGE;
 	my $feed_opts = get_feedopts($ctx);
@@ -58,30 +57,27 @@ sub generate_html_index {
 	my $title = $feed_opts->{description} || '';
 	$title = PublicInbox::Hval->new_oneline($title)->as_html;
 
-	my @messages;
-	my $git_dir = $ctx->{git_dir};
-	my $git = PublicInbox::GitCatFile->new($git_dir);
-	my ($first, $last) = each_recent_blob($ctx, sub {
-		mime_load_for_sort($git, $_[0], \@messages);
-	});
-	$git = undef; # destroy pipes.
-
-	my $th = PublicInbox::Thread->new(@messages);
-	$th->thread;
 	my $html = "<html><head><title>$title</title>" .
 		'<link rel="alternate" title="Atom feed"' . "\nhref=\"" .
 		$feed_opts->{atomurl} . "\"\ntype=\"application/atom+xml\"/>" .
 		'</head><body>' . PRE_WRAP;
 
-	# sort child messages in chronological order
-	$th->order(*PublicInbox::Thread::sort_ts);
-
-	# except we sort top-level messages reverse chronologically
-	my $state = [ $ctx->{srch}, {}, $first, 0 ];
-	for (PublicInbox::Thread::rsort_ts($th->rootset)) {
-		dump_msg($_, 0, \$html, $state)
-	}
+	my $state;
+	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+	my (undef, $last) = each_recent_blob($ctx, sub {
+		my ($path, $commit) = @_;
+		unless (defined $state) {
+			$state = [ $ctx->{srch}, {}, $commit, 0 ];
+		}
+		my $mime = do_cat_mail($git, $_[0]) or return 0;
+		my $t = eval { str2time($mime->header('Date')) };
+		defined($t) or $t = 0;
+		$mime->header_set('X-PI-TS', $t);
+		$html .= PublicInbox::View->index_entry($mime, 0, $state);
+		1;
+	});
 	Email::Address->purge_cache;
+	$git = undef; # destroy pipes.
 
 	my $footer = nav_footer($ctx->{cgi}, $last, $feed_opts, $state);
 	if ($footer) {
@@ -144,12 +140,12 @@ sub each_recent_blob {
 	my %deleted; # only an optimization at this point
 	my $last;
 	my $nr = 0;
-	my @commits = ();
+	my ($cur_commit, $first_commit, $last_commit);
 	while (my $line = <$log>) {
 		if ($line =~ /$addmsg/o) {
 			my $add = $1;
-			next if $deleted{$add};
-			$nr += $cb->($add);
+			next if $deleted{$add}; # optimization-only
+			$nr += $cb->($add, $cur_commit);
 			if ($nr >= $max) {
 				$last = 1;
 				last;
@@ -157,24 +153,23 @@ sub each_recent_blob {
 		} elsif ($line =~ /$delmsg/o) {
 			$deleted{$1} = 1;
 		} elsif ($line =~ /^commit (${hex}{7,40})/o) {
-			push @commits, $1;
+			$cur_commit = $1;
+			$first_commit = $1 unless defined $first_commit;
 		}
 	}
 
 	if ($last) {
 		while (my $line = <$log>) {
 			if ($line =~ /^commit (${hex}{7,40})/o) {
-				push @commits, $1;
+				$last_commit = $1;
 				last;
 			}
 		}
-	} else {
-		push @commits, undef;
 	}
 
 	close $log; # we may EPIPE here
 	# for pagination
-	($commits[0], $commits[-1]);
+	($first_commit, $last_commit);
 }
 
 # private functions below
@@ -279,16 +274,6 @@ sub add_to_feed {
 	1;
 }
 
-sub dump_msg {
-	my ($self, $level, $html, $state) = @_;
-	my $mime = $self->message;
-	if ($mime) {
-		$$html .= PublicInbox::View->index_entry($mime, $level, $state);
-	}
-	dump_msg($self->child, $level+1, $html, $state) if $self->child;
-	dump_msg($self->next, $level, $html, $state) if $self->next;
-}
-
 sub do_cat_mail {
 	my ($git, $path) = @_;
 	my $mime = eval {
@@ -298,15 +283,4 @@ sub do_cat_mail {
 	$@ ? undef : $mime;
 }
 
-sub mime_load_for_sort {
-	my ($git, $path, $messages) = @_;
-	my $mime = do_cat_mail($git, $path) or return 0;
-
-	my $t = eval { str2time($mime->header('Date')) };
-	defined($t) or $t = 0;
-	$mime->header_set('X-PI-TS', $t);
-	push @$messages, $mime;
-	1;
-}
-
 1;
-- 
EW


             reply	other threads:[~2015-08-20  2:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-20  2:57 Eric Wong [this message]
2015-08-20  2:57 ` [PATCH 02/11] feed: move timestamp parsing to view Eric Wong
2015-08-20  2:57 ` [PATCH 03/11] use tables for rendering comment nesting Eric Wong
2015-08-20  2:57 ` [PATCH 04/11] view: avoid nesting <a> tags from auto-linkification Eric Wong
2015-08-20  2:57 ` [PATCH 05/11] index: simplify main landing page if search-enabled Eric Wong
2015-08-20  2:57 ` [PATCH 06/11] search: avoid needless decode Eric Wong
2015-08-20  2:57 ` [PATCH 07/11] search: reject ghosts in all cases Eric Wong
2015-08-20  2:57 ` [PATCH 08/11] view: reduce memory usage when displaying large threads Eric Wong
2015-08-20  2:57 ` [PATCH 09/11] search: bump schema version to 5 for subject_path Eric Wong
2015-08-20  2:57 ` [PATCH 10/11] index: layout fix + title and Atom feed links at top Eric Wong
2015-08-20  2:57 ` [PATCH 11/11] view: do not fold top-level messages in thread 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=1440039443-27052-1-git-send-email-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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).