unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 11/12] nntp: xref: simplify sub signature
Date: Fri, 27 Nov 2020 09:52:53 +0000	[thread overview]
Message-ID: <20201127095254.21624-12-e@80x24.org> (raw)
In-Reply-To: <20201127095254.21624-1-e@80x24.org>

We'll be using the `xref3' table in extindex to speed up xref(),
and that'll require comparisons against $smsg->{blob}.  So pass
the entire $smsg through.
---
 lib/PublicInbox/NNTP.pm | 54 +++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 967a36a5..39ff5257 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -408,18 +408,19 @@ sub header_append ($$$) {
 	$hdr->header_set($k, @v, $v);
 }
 
-sub xref ($$$$) {
-	my ($self, $ng, $n, $mid) = @_;
-	my $ret = $self->{nntpd}->{servername} . " $ng->{newsgroup}:$n";
-
-	# num_for is pretty cheap and sometimes we'll lookup the existence
-	# of an article without getting even the OVER info.  In other words,
-	# I'm not sure if its worth optimizing by scanning To:/Cc: and
-	# PublicInbox::ExtMsg on the PSGI end is just as expensive
-	foreach my $other (@{$self->{nntpd}->{grouplist}}) {
-		next if $ng eq $other;
-		my $num = eval { $other->mm->num_for($mid) } or next;
-		$ret .= " $other->{newsgroup}:$num";
+sub xref ($$$) {
+	my ($self, $cur_ibx, $smsg) = @_;
+	my $nntpd = $self->{nntpd};
+	my $cur_ngname = $cur_ibx->{newsgroup};
+	my $ret = "$nntpd->{servername} $cur_ngname:$smsg->{num}";
+
+	my $mid = $smsg->{mid};
+	my $groups = $nntpd->{pi_config}->{-by_newsgroup};
+	for my $xngname (@{$nntpd->{groupnames}}) {
+		next if $cur_ngname eq $xngname;
+		my $xibx = $groups->{$xngname} or next;
+		my $num = eval { $xibx->mm->num_for($mid) } or next;
+		$ret .= " $xngname:$num";
 	}
 	$ret;
 }
@@ -443,7 +444,7 @@ sub set_nntp_headers ($$) {
 
 	# clobber some existing headers
 	my $ibx = $smsg->{-ibx};
-	my $xref = xref($smsg->{nntp}, $ibx, $smsg->{num}, $mid);
+	my $xref = xref($smsg->{nntp}, $ibx, $smsg);
 	$hdr->header_set('Xref', $xref);
 
 	# RFC 5536 3.1.4
@@ -724,12 +725,12 @@ sub mid_lookup ($$) {
 sub xref_range_i {
 	my ($self, $beg, $end) = @_;
 	my $ng = $self->{ng};
-	my $r = $ng->mm->msg_range($beg, $end);
-	@$r or return;
+	my $msgs = $ng->over->query_xover($$beg, $end);
+	scalar(@$msgs) or return;
+	$$beg = $msgs->[-1]->{num} + 1;
 	more($self, join("\r\n", map {
-		my $num = $_->[0];
-		"$num ".xref($self, $ng, $num, $_->[1]);
-	} @$r));
+		"$_->{num} ".xref($self, $ng, $_);
+	} @$msgs));
 	1;
 }
 
@@ -740,8 +741,9 @@ sub hdr_xref ($$$) { # optimize XHDR Xref [range] for rtin
 		my $mid = $1;
 		my ($ng, $n) = mid_lookup($self, $mid);
 		return r430 unless $n;
+		my $smsg = $ng->over->get_art($n) or return;
 		hdr_mid_response($self, $xhdr, $ng, $n, $range,
-				xref($self, $ng, $n, $mid));
+				xref($self, $ng, $smsg));
 	} else { # numeric range
 		$range = $self->{article} unless defined $range;
 		my $r = get_range($self, $range);
@@ -872,11 +874,11 @@ sub cmd_xrover ($;$) {
 	long_response($self, \&xrover_i, @$r);
 }
 
-sub over_line ($$$$) {
-	my ($self, $ng, $num, $smsg) = @_;
+sub over_line ($$$) {
+	my ($self, $ng, $smsg) = @_;
 	# n.b. field access and procedural calls can be
 	# 10%-15% faster than OO method calls:
-	my $s = join("\t", $num,
+	my $s = join("\t", $smsg->{num},
 		$smsg->{subject},
 		$smsg->{from},
 		PublicInbox::Smsg::date($smsg),
@@ -884,7 +886,7 @@ sub over_line ($$$$) {
 		$smsg->{references},
 		$smsg->{bytes},
 		$smsg->{lines},
-		"Xref: " . xref($self, $ng, $num, $smsg->{mid}));
+		"Xref: " . xref($self, $ng, $smsg));
 	utf8::encode($s);
 	$s
 }
@@ -899,8 +901,8 @@ sub cmd_over ($;$) {
 
 		# Only set article number column if it's the current group
 		my $self_ng = $self->{ng};
-		$n = 0 if (!$self_ng || $self_ng ne $ng);
-		more($self, over_line($self, $ng, $n, $smsg));
+		$smsg->{num} = 0 if (!$self_ng || $self_ng ne $ng);
+		more($self, over_line($self, $ng, $smsg));
 		'.';
 	} else {
 		cmd_xover($self, $range);
@@ -915,7 +917,7 @@ sub xover_i {
 
 	# OVERVIEW.FMT
 	more($self, join("\r\n", map {
-		over_line($self, $ng, $_->{num}, $_);
+		over_line($self, $ng, $_);
 		} @$msgs));
 	$$beg = $msgs->[-1]->{num} + 1;
 }

  parent reply	other threads:[~2020-11-27  9:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27  9:52 [PATCH 00/12] some NNTP-related fixes + speedups Eric Wong
2020-11-27  9:52 ` [PATCH 01/12] nntp: use Inbox->uidvalidity instead of ->mm->created_at Eric Wong
2020-11-27  9:52 ` [PATCH 02/12] nntpd: share {groups} hash with {-by_newsgroup} in Config Eric Wong
2020-11-27  9:52 ` [PATCH 03/12] mm: min/max: return 0 instead of undef Eric Wong
2020-11-27  9:52 ` [PATCH 04/12] nntp: use grep operation for wildmat matching Eric Wong
2020-11-27  9:52 ` [PATCH 05/12] nntp: NEWNEWS: speed up filtering Eric Wong
2020-11-27  9:52 ` [PATCH 06/12] miscsearch: implement ->newsgroup_matches Eric Wong
2020-11-27  9:52 ` [PATCH 07/12] nntp: LIST ACTIVE.TIMES use angle brackets around address Eric Wong
2020-11-27  9:52 ` [PATCH 08/12] nntp: move LIST iterators to long_response Eric Wong
2020-11-27  9:52 ` [PATCH 09/12] t/extsearch: show a more realistic case Eric Wong
2020-11-27  9:52 ` [PATCH 10/12] nntp: some minor golfing Eric Wong
2020-11-27  9:52 ` Eric Wong [this message]
2020-11-27  9:52 ` [PATCH 12/12] nntp: xref: use ->ALL extindex if available Eric Wong
2020-11-30 19:42   ` xref3 + NNTP problems Eric Wong
2020-11-30 23:37     ` [PATCH] nntp: make ->ALL Xref generation more fuzzy Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201127095254.21624-12-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).