-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}";
+ if (my $ALL = $nntpd->{pi_config}->ALL) {
+ if (my $ary = $ALL->nntp_xref_for($cur_ibx, $smsg)) {
+ $ret .= join(' ', '', @$ary) if scalar(@$ary);
+ }
+ # better off wrong than slow if there's thousands of groups,
+ # so no fallback to the slow path below:
+ } else { # slow path
+ 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";
+ }