user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 4/8] view: cleanup topic accumulation and dumping
  2020-02-15  9:46  7% [PATCH 0/8] some view cleanups and minor bugfixes Eric Wong
@ 2020-02-15  9:46  6% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-02-15  9:46 UTC (permalink / raw)
  To: meta

Avoid needlessly normalizing the subject when dumping, since
it's pushed into the @$topic array during accumulation in
normalized form.

We can also safely treat $smsg as a hashref and avoid
calling "->ds" as a method since we know we've got that
loaded via Over||Search and won't have to use Email::MIME
header lookup methods.
---
 lib/PublicInbox/View.pm | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index f0446723..e586b068 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -1039,35 +1039,32 @@ sub sort_ds {
 sub acc_topic { # walk_thread callback
 	my ($ctx, $level, $node) = @_;
 	my $mid = $node->{id};
-	my $x = $node->{smsg} || $ctx->{-inbox}->smsg_by_mid($mid);
-	my ($subj, $ds);
-	my $topic;
-	if ($x) {
-		$subj = $x->subject;
-		$subj = subject_normalized($subj);
+	my $smsg = $node->{smsg} // $ctx->{-inbox}->smsg_by_mid($mid);
+	if ($smsg) {
+		my $subj = subject_normalized($smsg->subject);
 		$subj = '(no subject)' if $subj eq '';
-		$ds = $x->ds;
-		if ($level == 0) {
-			$topic = [ $ds, 1, { $subj => $mid }, $subj ];
+		my $ds = $smsg->{ds};
+		if ($level == 0) { # new, top-level topic
+			my $topic = [ $ds, 1, { $subj => $mid }, $subj ];
 			$ctx->{-cur_topic} = $topic;
 			push @{$ctx->{order}}, $topic;
 			return 1;
 		}
 
-		$topic = $ctx->{-cur_topic}; # should never be undef
+		# continue existing topic
+		my $topic = $ctx->{-cur_topic}; # should never be undef
 		$topic->[0] = $ds if $ds > $topic->[0];
-		$topic->[1]++;
+		$topic->[1]++; # bump N+ message counter
 		my $seen = $topic->[2];
 		if (scalar(@$topic) == 3) { # parent was a ghost
 			push @$topic, $subj;
-		} elsif (!$seen->{$subj}) {
-			push @$topic, $level, $subj;
+		} elsif (!defined($seen->{$subj})) {
+			push @$topic, $level, $subj; # @extra messages
 		}
 		$seen->{$subj} = $mid; # latest for subject
 	} else { # ghost message
 		return 1 if $level != 0; # ignore child ghosts
-		$topic = [ -666, 0, {} ];
-		$ctx->{-cur_topic} = $topic;
+		my $topic = $ctx->{-cur_topic} = [ -666, 0, {} ];
 		push @{$ctx->{order}}, $topic;
 	}
 	1;
@@ -1087,7 +1084,7 @@ sub dump_topics {
 
 	# sort by recency, this allows new posts to "bump" old topics...
 	foreach my $topic (sort { $b->[0] <=> $a->[0] } @$order) {
-		my ($ds, $n, $seen, $top_subj, @ex) = @$topic;
+		my ($ds, $n, $seen, $top_subj, @extra) = @$topic;
 		@$topic = ();
 		next unless defined $top_subj;  # ghost topic
 		my $mid = delete $seen->{$top_subj};
@@ -1111,19 +1108,19 @@ sub dump_topics {
 		my $atom = qq(<a\nhref="$href/t.atom">Atom</a>);
 		my $s = "<a\nhref=\"$href/T/$anchor\">$top_subj</a>\n" .
 			" $ds UTC $n - $mbox / $atom\n";
-		for (my $i = 0; $i < scalar(@ex); $i += 2) {
-			my $level = $ex[$i];
-			my $subj = $ex[$i + 1];
+		for (my $i = 0; $i < scalar(@extra); $i += 2) {
+			my $level = $extra[$i];
+			my $subj = $extra[$i + 1]; # already normalized
 			$mid = delete $seen->{$subj};
-			my @subj = split(/ /, subject_normalized($subj));
+			my @subj = split(/ /, $subj);
 			my @next_prev = @subj; # full copy
 			my $omit = dedupe_subject($prev_subj, \@subj, ' &#34;');
 			$prev_subj = \@next_prev;
-			$subj = ascii_html(join(' ', @subj));
+			$subj = ascii_html($subj);
 			obfuscate_addrs($obfs_ibx, $subj) if $obfs_ibx;
 			$href = mid_escape($mid);
 			$s .= indent_for($level) . TCHILD;
-			$s .= "<a\nhref=\"$href/T/#u\">$subj</a>$omit\n";
+			$s .= qq(<a\nhref="$href/T/#u">$subj</a>$omit\n);
 		}
 		push @out, $s;
 	}

^ permalink raw reply related	[relevance 6%]

* [PATCH 0/8] some view cleanups and minor bugfixes
@ 2020-02-15  9:46  7% Eric Wong
  2020-02-15  9:46  6% ` [PATCH 4/8] view: cleanup topic accumulation and dumping Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-02-15  9:46 UTC (permalink / raw)
  To: meta

Pretty insignificant, but the diffstat makes me happy :>

Eric Wong (8):
  view: remove mhref arg from multipart_text_as_html
  view: single id="t" for multi-Subject messages
  view: dump_topics: better naming of top Subject
  view: cleanup topic accumulation and dumping
  view,searchview: avoid smsg method calls when using SQLite/Xapian
  view: escape Subject HTML directly
  view: escape ampersand in Message-IDs
  view: remove last Hval->new caller

 lib/PublicInbox/ExtMsg.pm        |  19 ++--
 lib/PublicInbox/Hval.pm          |  28 +-----
 lib/PublicInbox/Linkify.pm       |   9 +-
 lib/PublicInbox/Reply.pm         |   6 +-
 lib/PublicInbox/SearchView.pm    |  10 +--
 lib/PublicInbox/View.pm          | 144 ++++++++++++++-----------------
 lib/PublicInbox/WwwAtomStream.pm |  12 +--
 t/psgi_bad_mids.t                |   9 +-
 xt/perf-msgview.t                |   3 +-
 9 files changed, 104 insertions(+), 136 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-02-15  9:46  7% [PATCH 0/8] some view cleanups and minor bugfixes Eric Wong
2020-02-15  9:46  6% ` [PATCH 4/8] view: cleanup topic accumulation and dumping Eric Wong

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