]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
nntpd: remove redundant {groups} shortcut
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index c014eff0a4e48b5685c3a10abfe5a4a876b0c493..3b16a66abad72181ef940339ce9e2691d169a6ce 100644 (file)
@@ -321,7 +321,7 @@ sub ngpat2re (;$) {
 sub newnews_i {
        my ($self, $names, $ts, $prev) = @_;
        my $ngname = $names->[0];
-       if (my $ibx = $self->{nntpd}->{groups}->{$ngname}) {
+       if (my $ibx = $self->{nntpd}->{pi_config}->{-by_newsgroup}->{$ngname}) {
                if (my $over = $ibx->over) {
                        my $msgs = $over->query_ts($ts, $$prev);
                        if (scalar @$msgs) {
@@ -360,13 +360,13 @@ sub cmd_newnews ($$$$;$$) {
 
 sub cmd_group ($$) {
        my ($self, $group) = @_;
-       my $no_such = '411 no such news group';
        my $nntpd = $self->{nntpd};
-       my $ng = $nntpd->{groups}->{$group} or return $no_such;
+       my $ibx = $nntpd->{pi_config}->{-by_newsgroup}->{$group} or
+               return '411 no such news group';
        $nntpd->idler_start;
 
-       $self->{ng} = $ng;
-       my ($min, $max) = $ng->mm->minmax;
+       $self->{ng} = $ibx;
+       my ($min, $max) = $ibx->mm->minmax;
        $self->{article} = $min;
        my $est_size = $max - $min;
        "211 $est_size $min $max $group";
@@ -743,7 +743,7 @@ EOF
                }
                # no warning here, $mid is just invalid
        } else { # slow path for non-ALL users
-               foreach my $ibx (values %{$self->{nntpd}->{groups}}) {
+               for my $ibx (values %{$pi_cfg->{-by_newsgroup}}) {
                        next if defined $self_ng && $ibx eq $self_ng;
                        my $n = $ibx->mm->num_for($mid);
                        return ($ibx, $n) if defined $n;
@@ -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") }