]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: stream mboxrd in descending docid order
authorEric Wong <e@80x24.org>
Mon, 8 Feb 2021 18:33:39 +0000 (08:33 -1000)
committerEric Wong <e@80x24.org>
Tue, 9 Feb 2021 07:51:03 +0000 (07:51 +0000)
Order doesn't matter when users are completely downloading
mboxrds onto the FS and then opening them with an MUA.  The
MUA is expected to sort the results in the user's preferred
order.

However, lei can start streaming the results to its destination
Maildir (or eventually IMAP/JMAP mailbox) with an MUA already
open.  This will let users see recent results sooner in their
MUA, as those tend to have a higher docid.  This matches the
behavior of the HTML results, as well.

As a bonus, this is around ~5% faster in a one-off, informal
test case with 66k results.  I expect this to hold true in all
all cases since git has always optimized storage to favor recent
objects.

lib/PublicInbox/Mbox.pm
lib/PublicInbox/Search.pm

index 1fca356b60ea6a6429bf246ffeefe2fd7f3f5421..94f733bcc8504f3e7f064e20b96d3f6e2f9e35f5 100644 (file)
@@ -235,7 +235,7 @@ sub mbox_all {
        my $over = $ctx->{ibx}->over or
                return PublicInbox::WWW::need($ctx, 'Overview');
 
-       my $qopts = $ctx->{qopts} = { relevance => -1 }; # ORDER BY docid ASC
+       my $qopts = $ctx->{qopts} = { relevance => -2 }; # ORDER BY docid DESC
        $qopts->{threads} = 1 if $q->{t};
        my $mset = $srch->mset($q_string, $qopts);
        $qopts->{offset} = $mset->size or
index aa737d63b5f64b7d30df764b6b34ceaf2e3044b0..76a270bca0c01e9c6121c530ff405594f04d6114 100644 (file)
@@ -407,18 +407,17 @@ sub _enquire_once { # retry_reopen callback
        my $enquire = $X{Enquire}->new($xdb);
        $enquire->set_query($query);
        $opts ||= {};
-        my $desc = !$opts->{asc};
        my $rel = $opts->{relevance} // 0;
-       if ($rel == -1) { # ORDER BY docid/UID
+       if ($rel == -2) { # ORDER BY docid/UID (highest first)
+               $enquire->set_weighting_scheme($X{BoolWeight}->new);
+               $enquire->set_docid_order($ENQ_DESCENDING);
+       } elsif ($rel == -1) { # ORDER BY docid/UID (lowest first)
                $enquire->set_weighting_scheme($X{BoolWeight}->new);
                $enquire->set_docid_order($ENQ_ASCENDING);
        } elsif ($rel == 0) {
-               $enquire->set_sort_by_value_then_relevance(TS, $desc);
-       } elsif ($rel == -2) {
-               $enquire->set_weighting_scheme($X{BoolWeight}->new);
-               $enquire->set_docid_order($ENQ_DESCENDING);
+               $enquire->set_sort_by_value_then_relevance(TS, !$opts->{asc});
        } else { # rel > 0
-               $enquire->set_sort_by_relevance_then_value(TS, $desc);
+               $enquire->set_sort_by_relevance_then_value(TS, !$opts->{asc});
        }
 
        # `mairix -t / --threads' or JMAP collapseThreads