From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 6/7] thread: last Reference always wins
Date: Sat, 10 Dec 2016 03:43:04 +0000 [thread overview]
Message-ID: <20161210034305.2654-7-e@80x24.org> (raw)
In-Reply-To: <20161210034305.2654-1-e@80x24.org>
Since we use SearchMsg from Xapian data, we can be
assured we do not get self-referential {references}
field.
However, we may need to be more careful when checking
has_descendent for loops, as blindly calling add_child
could open us up to that possibility...
---
lib/PublicInbox/SearchThread.pm | 13 ++++++++-----
t/thread-cycle.t | 8 --------
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm
index ee35f0d..601a84b 100644
--- a/lib/PublicInbox/SearchThread.pm
+++ b/lib/PublicInbox/SearchThread.pm
@@ -52,6 +52,10 @@ sub _add_message ($$) {
# B. For each element in the message's References field:
defined(my $refs = $smsg->{references}) or return;
+ # This loop exists to help fill in gaps left from missing
+ # messages. It is not needed in a perfect world where
+ # everything is perfectly referenced, only the last ref
+ # matters.
my $prev;
foreach my $ref ($refs =~ m/<([^>]+)>/g) {
# Find a Container object for the given Message-ID
@@ -74,10 +78,8 @@ sub _add_message ($$) {
}
# C. Set the parent of this message to be the last element in
- # References...
- if ($prev && !$this->has_descendent($prev)) { # would loop
- $prev->add_child($this)
- }
+ # References.
+ $prev->add_child($this) if defined $prev;
}
sub order {
@@ -127,8 +129,9 @@ sub add_child {
sub has_descendent {
my ($self, $child) = @_;
+ my %seen; # loop prevention XXX may not be necessary
while ($child) {
- return 1 if $self == $child;
+ return 1 if $self == $child || $seen{$child}++;
$child = $child->{parent};
}
0;
diff --git a/t/thread-cycle.t b/t/thread-cycle.t
index 0e1ecfe..b084449 100644
--- a/t/thread-cycle.t
+++ b/t/thread-cycle.t
@@ -70,14 +70,6 @@ SKIP: {
is($check, $st, 'Mail::Thread output matches');
}
-@msgs = map { bless $_, 'PublicInbox::SearchMsg' } (
- { mid => 'a@b' },
- { mid => 'b@c', references => '<a@b> <b@c>' },
- { mid => 'd@e', references => '<d@e>' },
-);
-
-is(thread_to_s(\@msgs), "a\@b\n b\@c\nd\@e\n", 'ok with self-references');
-
done_testing();
sub thread_to_s {
--
EW
next prev parent reply other threads:[~2016-12-10 3:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-10 3:42 [PATCH 0/7] message threading fixes for WWW UI Eric Wong
2016-12-10 3:42 ` [PATCH 1/7] search: favor In-Reply-To over last References iff IRT exists Eric Wong
2016-12-10 3:43 ` [PATCH 2/7] view: favor SearchMsg for In-Reply-To over Email::MIME Eric Wong
2016-12-10 3:43 ` [PATCH 3/7] thread: fix comment describing its existence Eric Wong
2016-12-10 3:43 ` [PATCH 4/7] view: reduce indentation for skeleton generation Eric Wong
2016-12-10 3:43 ` [PATCH 5/7] view: skip ghosts with no direct children Eric Wong
2016-12-10 3:43 ` Eric Wong [this message]
2016-12-10 3:43 ` [PATCH 7/7] search: always sort thread results in ascending time order 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: http://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=20161210034305.2654-7-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).