about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchThread.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-10 01:09:50 +0000
committerEric Wong <e@80x24.org>2016-12-10 03:29:07 +0000
commitc6a8fdf71e2c336f6e591c6f4005c8e922c8f2df (patch)
treefd15d7ce7045145797a3161df26b5e20d336bd7f /lib/PublicInbox/SearchThread.pm
parentdecbc59daa3b08e58e749b5bd88a9d0cbbb7e14a (diff)
downloadpublic-inbox-c6a8fdf71e2c336f6e591c6f4005c8e922c8f2df.tar.gz
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...
Diffstat (limited to 'lib/PublicInbox/SearchThread.pm')
-rw-r--r--lib/PublicInbox/SearchThread.pm13
1 files changed, 8 insertions, 5 deletions
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;