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 74C021F4F8; Fri, 14 Oct 2016 21:17:46 +0000 (UTC) Date: Fri, 14 Oct 2016 21:17:46 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] thread: reinstates stable ordering when ghosts are present Message-ID: <20161014211746.GA29065@dcvr> References: <20161005235722.14857-1-e@80x24.org> <20161005235722.14857-14-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161005235722.14857-14-e@80x24.org> List-Id: This reverts commit 3c9dd6619f825f0515e7e4afa1bd55c99c1a68d3 ("thread: fix sorting without topmost") and reinstates the "topmost" routine for sorting purposes. --- lib/PublicInbox/SearchThread.pm | 10 ++++++++++ lib/PublicInbox/SearchView.pm | 5 +++-- lib/PublicInbox/View.pm | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm index 24a56d2..fe70406 100644 --- a/lib/PublicInbox/SearchThread.pm +++ b/lib/PublicInbox/SearchThread.pm @@ -98,6 +98,16 @@ sub new { }, $_[0]; } +sub topmost { + my ($self) = @_; + my @q = ($self); + while (my $cont = shift @q) { + return $cont if $cont->{smsg}; + push @q, values %{$cont->{children}}; + } + undef; +} + sub add_child { my ($self, $child) = @_; croak "Cowardly refusing to become my own parent: $self" diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index cfe6dff..ebeb41f 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -155,8 +155,9 @@ sub mset_thread { $th->thread; if ($q->{r}) { # order by relevance $th->order(sub { - [ sort { ( $pct{$b->{id}} || 0) <=> - ( $pct{$a->{id}} || 0) + [ sort { (eval { $pct{$b->topmost->{id}} } || 0) + <=> + (eval { $pct{$a->topmost->{id}} } || 0) } @{$_[0]} ]; }); } else { # order by time (default for threaded view) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 0f00458..5d5808f 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -852,8 +852,8 @@ sub skel_dump { sub sort_ts { [ sort { - (eval { $a->{smsg}->ts } || 0) <=> - (eval { $b->{smsg}->ts } || 0) + (eval { $a->topmost->{smsg}->ts } || 0) <=> + (eval { $b->topmost->{smsg}->ts } || 0) } @{$_[0]} ]; } -- EW