about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-21 02:58:57 +0000
committerEric Wong <e@80x24.org>2016-06-21 03:06:57 +0000
commit76d8f68dc273e54809ad69cfe49e141003f790ef (patch)
tree9d8de044936c18345a569684c7941de030819b74 /lib/PublicInbox
parent377e75d7a2e9eaa9fdd77dfea9dc202b3bdbefc4 (diff)
downloadpublic-inbox-76d8f68dc273e54809ad69cfe49e141003f790ef.tar.gz
Recursion can cause problems, so do our best to avoid it
even in the topic index.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/View.pm16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index bc4a4432..8075e4ae 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;
         }