]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: XPATH uses ->ALL extindex, too
authorEric Wong <e@80x24.org>
Sat, 28 Nov 2020 05:09:15 +0000 (05:09 +0000)
committerEric Wong <e@80x24.org>
Sun, 29 Nov 2020 02:25:50 +0000 (02:25 +0000)
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.

lib/PublicInbox/NNTP.pm
t/extsearch.t

index c014eff0a4e48b5685c3a10abfe5a4a876b0c493..d314a3d1ebcf0bc74001593319b93448c203cb3d 100644 (file)
@@ -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") }
index f585555807f5cc4975115101a1848f010ce3868e..4f1dbadf8d60d28fecbdce872d46fddbc1d86f10 100644 (file)
@@ -74,9 +74,11 @@ EOF
 SKIP: {
        require_mods(qw(Net::NNTP), 1);
        my ($out, $err) = ("$home/nntpd.out.log", "$home/nntpd.err.log");
-       my $cmd = [ '-nntpd', '-W0' ]; #, "--stdout=$out", "--stderr=$err" ];
+       my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        my $td = start_script($cmd, undef, { 3 => $sock });
        my $n = Net::NNTP->new($host_port);
+       my @xp = $n->xpath('<testmessage@example.com>');
+       is_deeply(\@xp, [ qw(v1.example/1 v2.example/1) ]);
        $n->group('v1.example');
        my $res = $n->head(1);
        @$res = grep(/^Xref: /, @$res);