about summary refs log tree commit homepage
path: root/lib/PublicInbox/NNTP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-11-28 05:09:15 +0000
committerEric Wong <e@80x24.org>2020-11-29 02:25:50 +0000
commit2d3fc25afe7435992236ac143039b24248c5e74d (patch)
tree45ab6a07e5575fb59f2947eaeddf82e561eed8c3 /lib/PublicInbox/NNTP.pm
parent4b3294b7d5513db0368745f7c6e8e923fbf2a744 (diff)
downloadpublic-inbox-2d3fc25afe7435992236ac143039b24248c5e74d.tar.gz
nntp: XPATH uses ->ALL extindex, too
Another 30-40% speedup when testing against a local
lore.kernel.org mirror.  In either case, we'll consistently sort
the response for ease-of-testing and client-side
cache-friendliness.
Diffstat (limited to 'lib/PublicInbox/NNTP.pm')
-rw-r--r--lib/PublicInbox/NNTP.pm24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index c014eff0..d314a3d1 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -994,12 +994,28 @@ sub cmd_xpath ($$) {
         return r501 unless $mid =~ $ONE_MSGID;
         $mid = $1;
         my @paths;
-        foreach my $ng (values %{$self->{nntpd}->{groups}}) {
-                my $n = $ng->mm->num_for($mid);
-                push @paths, "$ng->{newsgroup}/$n" if defined $n;
+        my $pi_cfg = $self->{nntpd}->{pi_config};
+        my $groups = $pi_cfg->{-by_newsgroup};
+        if (my $ALL = $pi_cfg->ALL) {
+                my ($id, $prev, %seen);
+                while (my $smsg = $ALL->over->next_by_mid($mid, \$id, \$prev)) {
+                        my $xr3 = $ALL->over->get_xref3($smsg->{num});
+                        for my $x (@$xr3) {
+                                my ($ngname, $n) = split(/:/, $x);
+                                $x = "$ngname/$n";
+                                if ($groups->{$ngname} && !$seen{$x}++) {
+                                        push(@paths, $x);
+                                }
+                        }
+                }
+        } else { # slow path, no point in using long_response
+                for my $ibx (values %$groups) {
+                        my $n = $ibx->mm->num_for($mid) // next;
+                        push @paths, "$ibx->{newsgroup}/$n";
+                }
         }
         return '430 no such article on server' unless @paths;
-        '223 '.join(' ', @paths);
+        '223 '.join(' ', sort(@paths));
 }
 
 sub res ($$) { do_write($_[0], $_[1] . "\r\n") }