From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7A01720191 for ; Tue, 21 Jun 2016 03:12:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 6/7] view: avoid recursion in topic index Date: Tue, 21 Jun 2016 03:12:00 +0000 Message-Id: <20160621031201.28089-7-e@80x24.org> In-Reply-To: <20160621031201.28089-1-e@80x24.org> References: <20160621031201.28089-1-e@80x24.org> List-Id: 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; }