]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NewsGroup.pm
config: remove try_cat
[public-inbox.git] / lib / PublicInbox / NewsGroup.pm
index b20180e6667aceebd0a1feb516118f38603fa69f..500f61e3a9b8d82c326025f81f3e9fd0e316e318 100644 (file)
@@ -13,31 +13,34 @@ require PublicInbox::Search;
 require PublicInbox::Git;
 
 sub new {
-       my ($class, $name, $git_dir, $address) = @_;
+       my ($class, $newsgroup, $git_dir, $address, $url) = @_;
+
+       # first email address is preferred
        $address = $address->[0] if ref($address);
+       if ($url) {
+               # assume protocol-relative URLs which start with '//' means
+               # the server supports both HTTP and HTTPS, favor HTTPS.
+               $url = "https:$url" if $url =~ m!\A//!;
+               $url .= '/' if $url !~ m!/\z!;
+       }
        my $self = bless {
-               name => $name,
+               newsgroup => $newsgroup,
                git_dir => $git_dir,
                address => $address,
+               url => $url,
        }, $class;
        $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
        $self;
 }
 
-sub defer_weaken {
-       my ($self, $field) = @_;
-       Danga::Socket->AddTimer(30, sub { weaken($self->{$field}) });
+sub weaken_all {
+       my ($self) = @_;
+       weaken($self->{$_}) foreach qw(gcf mm search);
 }
 
 sub gcf {
        my ($self) = @_;
-       $self->{gcf} ||= eval {
-               my $gcf = PublicInbox::Git->new($self->{git_dir});
-
-               # git repos may be repacked and old packs unlinked
-               defer_weaken($self, 'gcf');
-               $gcf;
-       };
+       $self->{gcf} ||= eval { PublicInbox::Git->new($self->{git_dir}) };
 }
 
 sub usable {
@@ -50,24 +53,12 @@ sub usable {
 
 sub mm {
        my ($self) = @_;
-       $self->{mm} ||= eval {
-               my $mm = PublicInbox::Msgmap->new($self->{git_dir});
-
-               # may be needed if we run low on handles
-               defer_weaken($self, 'mm');
-               $mm;
-       };
+       $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{git_dir}) };
 }
 
 sub search {
        my ($self) = @_;
-       $self->{search} ||= eval {
-               my $search = PublicInbox::Search->new($self->{git_dir});
-
-               # may be needed if we run low on handles
-               defer_weaken($self, 'search');
-               $search;
-       };
+       $self->{search} ||= eval { PublicInbox::Search->new($self->{git_dir}) };
 }
 
 sub description {