This fills in the internal lookup hashes and simplifies
callers.
- my $rv = $self->{-by_name}->{$name};
- return $rv if $rv;
- $rv = _fill($self, "publicinbox.$name") or return;
+ $self->{-by_name}->{$name} || _fill($self, "publicinbox.$name");
+}
+
+sub each_inbox {
+ my ($self, $cb) = @_;
+ my %seen;
+ foreach my $k (keys %$self) {
+ $k =~ /\Apublicinbox\.([A-Z0-9a-z-]+)\.mainrepo\z/ or next;
+ next if $seen{$1};
+ $seen{$1} = 1;
+ my $ibx = lookup_name($self, $1) or next;
+ $cb->($ibx);
+ }
eval { require PublicInbox::Search };
my $have_xap = $@ ? 0 : 1;
eval { require PublicInbox::Search };
my $have_xap = $@ ? 0 : 1;
+ my (@nox, @ibx, @found);
- foreach my $k (keys %$pi_config) {
- $k =~ /\Apublicinbox\.([A-Z0-9a-z-]+)\.url\z/ or next;
- my $name = $1;
- next if $name eq $cur->{name};
- my $other = $pi_config->lookup_name($name) or next;
- next unless $other->base_url;
+ $pi_config->each_inbox(sub {
+ my ($other) = @_;
+ return if $other->{name} eq $cur->{name} || !$other->base_url;
my $s = $other->search;
if (!$s) {
push @nox, $other;
my $s = $other->search;
if (!$s) {
push @nox, $other;
}
# try to find the URL with Xapian to avoid forking
}
# try to find the URL with Xapian to avoid forking
if ($@) {
# xapian not configured properly for this repo
push @nox, $other;
if ($@) {
# xapian not configured properly for this repo
push @nox, $other;
- return r302($other, $mid) if defined $doc_id;
+ if (defined $doc_id) {
+ push @found, $other;
+ } else {
+ # no point in trying the fork fallback if we
+ # know Xapian is up-to-date but missing the
+ # message in the current repo
+ push @ibx, $other;
+ }
+ });
- # no point in trying the fork fallback if we
- # know Xapian is up-to-date but missing the
- # message in the current repo
- push @ibx, $other;
- }
+ # TODO: multiple hits
+ return r302($found[0], $mid) if @found;
# Xapian not installed or configured for some repos,
# do a full MID check:
# Xapian not installed or configured for some repos,
# do a full MID check:
my $pi_config = PublicInbox::Config->new;
my $new = {};
my @list;
my $pi_config = PublicInbox::Config->new;
my $new = {};
my @list;
- foreach my $k (keys %$pi_config) {
- $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
- my $name = $1;
- my $git_dir = $pi_config->{$k};
- my $ngname = $pi_config->{"publicinbox.$name.newsgroup"};
- next unless defined $ngname;
- next if ($ngname eq ''); # disabled
- my $ng = $pi_config->lookup_newsgroup($ngname) or next;
-
- # Only valid if msgmap and search works
- if ($ng->nntp_usable) {
+ $pi_config->each_inbox(sub {
+ my ($ng) = @_;
+ my $ngname = $ng->{newsgroup} or next;
+ if (ref $ngname) {
+ warn 'multiple newsgroups not supported: '.
+ join(', ', @$ngname). "\n";
+ } elsif ($ng->nntp_usable) {
+ # Only valid if msgmap and search works
$new->{$ngname} = $ng;
push @list, $ng;
}
$new->{$ngname} = $ng;
push @list, $ng;
}
@list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
$self->{grouplist} = \@list;
# this will destroy old groups that got deleted
@list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
$self->{grouplist} = \@list;
# this will destroy old groups that got deleted