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] view: fix topic threading when ghosts are present
@ 2016-06-22  6:06  6% Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2016-06-22  6:06 UTC (permalink / raw)
  To: meta

This fixes a bug where a message replying to a ghost would
accidentally be added to the wrong topic in the index/topic
view.

Before commit 76d8f68dc273e54809ad69cfe49e141003f790ef ("view:
avoid recursion in topic index"), we would refuse to indent a
topic which started with a ghost which hid the problem.  Now we
inform the user the thread started elsewhere.
---
 lib/PublicInbox/View.pm | 47 ++++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 8e81391..8d2e542 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -748,8 +748,7 @@ sub sort_ts {
 }
 
 sub _tryload_ghost ($$) {
-	my ($srch, $node) = @_;
-	my $mid = $node->messageid;
+	my ($srch, $mid) = @_;
 	my $smsg = $srch->lookup_mail($mid) or return;
 	$smsg->mini_mime;
 }
@@ -758,30 +757,25 @@ sub _tryload_ghost ($$) {
 # returns 1 if done, undef if not
 sub add_topic {
 	my ($state, $level, $node) = @_;
-	my $child_adjust = 1;
 	my $srch = $state->{srch};
-	my $x = $node->message || _tryload_ghost($srch, $node);
+	my $mid = $node->messageid;
+	my $x = $node->message || _tryload_ghost($srch, $mid);
+	my ($subj, $ts);
 	if ($x) {
 		$x = $x->header_obj;
-		my $subj;
-
 		$subj = $x->header('Subject');
 		$subj = $srch->subject_normalized($subj);
-
-		if (++$state->{subjs}->{$subj} == 1) {
-			push @{$state->{order}}, [ $level, $subj ];
-		}
-
-		my $mid = mid_clean($x->header_raw('Message-ID'));
-
-		my $ts = $x->header('X-PI-TS');
-		my $exist = $state->{latest}->{$subj};
-		if (!$exist || $exist->[1] < $ts) {
-			$state->{latest}->{$subj} = [ $mid, $ts ];
-		}
-	} else {
-		# ghost message, do not bump level
-		$child_adjust = 0;
+		$ts = $x->header('X-PI-TS');
+	} else { # ghost message, do not bump level
+		$ts = -666;
+		$subj = "<$mid>";
+	}
+	if (++$state->{subjs}->{$subj} == 1) {
+		push @{$state->{order}}, [ $level, $subj ];
+	}
+	my $exist = $state->{latest}->{$subj};
+	if (!$exist || $exist->[1] < $ts) {
+		$state->{latest}->{$subj} = [ $mid, $ts ];
 	}
 }
 
@@ -802,7 +796,6 @@ sub emit_topics {
 		my $n = delete $subjs->{$subj};
 		my ($mid, $ts) = @{delete $latest->{$subj}};
 		$mid = PublicInbox::Hval->new_msgid($mid)->as_href;
-		$subj = PublicInbox::Hval->new($subj)->as_html;
 		$pfx = indent_for($level);
 		my $nl = $level == $prev ? "\n" : '';
 		if ($nl && $cur) {
@@ -811,10 +804,14 @@ sub emit_topics {
 		}
 		$cur ||= [ $ts, '' ];
 		$cur->[0] = $ts if $ts > $cur->[0];
-		$cur->[1] .= $nl . $pfx . th_pfx($level) .
-				"<a\nhref=\"$mid/t/#u\"><b>" .
-				$subj . "</b></a>\n";
+		$cur->[1] .= $nl . $pfx . th_pfx($level);
+		if ($ts == -666) { # ghost
+			$cur->[1] .= ghost_parent('', $mid) . "\n";
+			next; # child will have mbox / atom link
+		}
 
+		$subj = PublicInbox::Hval->new($subj)->as_html;
+		$cur->[1] .= "<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
 		$ts = fmt_ts($ts);
 		my $attr = " $ts UTC";
 

^ permalink raw reply related	[relevance 6%]

* [PATCH 6/7] view: avoid recursion in topic index
  2016-06-21  3:11  7% [PATCH 0/7] www: avoid recursion for thread walking Eric Wong
@ 2016-06-21  3:12  7% ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2016-06-21  3:12 UTC (permalink / raw)
  To: meta

Recursion can cause problems, so do our best to avoid it
even in the topic index.
---
 lib/PublicInbox/View.pm | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index bc4a443..8075e4a 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -757,8 +757,7 @@ sub _tryload_ghost ($$) {
 # accumulate recent topics if search is supported
 # returns 1 if done, undef if not
 sub add_topic {
-	my ($state, $node, $level) = @_;
-	return unless $node;
+	my ($state, $level, $node) = @_;
 	my $child_adjust = 1;
 	my $srch = $state->{srch};
 	my $x = $node->message || _tryload_ghost($srch, $node);
@@ -784,9 +783,6 @@ sub add_topic {
 		# ghost message, do not bump level
 		$child_adjust = 0;
 	}
-
-	add_topic($state, $node->child, $level + $child_adjust);
-	add_topic($state, $node->next, $level);
 }
 
 sub emit_topics {
@@ -850,9 +846,13 @@ sub emit_index_topics {
 	while (scalar @{$state->{order}} < $max) {
 		my $sres = $state->{srch}->query('', \%opts);
 		my $nr = scalar @{$sres->{msgs}} or last;
-
-		for (thread_results(load_results($sres))->rootset) {
-			add_topic($state, $_, 0);
+		$sres = load_results($sres);
+		my @q = map { (0, $_) } thread_results($sres)->rootset;
+		while (@q) {
+			my $level = shift @q;
+			my $node = shift @q or next;
+			add_topic($state, $level, $node);
+			unshift @q, $level+1, $node->child, $level, $node->next;
 		}
 		$opts{offset} += $nr;
 	}

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/7] www: avoid recursion for thread walking
@ 2016-06-21  3:11  7% Eric Wong
  2016-06-21  3:12  7% ` [PATCH 6/7] view: avoid recursion in topic index Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2016-06-21  3:11 UTC (permalink / raw)
  To: meta

Deep message threads can cause problems for perl since stack
seems to be much more expensive than arrays.  Switch to a
non-recursive thread walking design and commonalize some
common idioms, too.

Eric Wong (7):
      view: remove upfx parameter from thread skeleton dump
      view: remove dst parameter from thread skeleton dump
      view: remove recursion from thread skeleton dump
      view: remove recursion from expanded thread view
      searchview: remove recursion from thread view
      view: avoid recursion in topic index
      view: common thread walking interface

 lib/PublicInbox/SearchView.pm |  9 ++------
 lib/PublicInbox/View.pm       | 53 +++++++++++++++++++++----------------------
 2 files changed, 28 insertions(+), 34 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-21  3:11  7% [PATCH 0/7] www: avoid recursion for thread walking Eric Wong
2016-06-21  3:12  7% ` [PATCH 6/7] view: avoid recursion in topic index Eric Wong
2016-06-22  6:06  6% [PATCH] view: fix topic threading when ghosts are present 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).