user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH] www: stream mboxrd in descending docid order
@ 2021-02-08 18:33 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-02-08 18:33 UTC (permalink / raw)
  To: meta

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   |  2 +-
 lib/PublicInbox/Search.pm | 13 ++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 1fca356b..94f733bc 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -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
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index aa737d63..76a270bc 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-08 18:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08 18:33 [PATCH] www: stream mboxrd in descending docid order Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git