From c6a8fdf71e2c336f6e591c6f4005c8e922c8f2df Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 10 Dec 2016 01:09:50 +0000 Subject: thread: last Reference always wins 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 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm index ee35f0d0..601a84b0 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; -- cgit v1.2.3-24-ge0c7