1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::NewsGroup;
6 use fields qw(name git_dir address domain mm gcf search);
7 use Scalar::Util qw(weaken);
9 require PublicInbox::Msgmap;
10 require PublicInbox::GitCatFile;
13 my ($class, $name, $git_dir, $address) = @_;
14 my $self = fields::new($class);
15 $self->{name} = $name;
16 $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
17 $self->{git_dir} = $git_dir;
18 $self->{address} = $address;
23 my ($self, $field) = @_;
24 Danga::Socket->AddTimer(30, sub { weaken($self->{$field}) });
29 $self->{gcf} ||= eval {
30 my $gcf = PublicInbox::GitCatFile->new($self->{git_dir});
32 # git repos may be repacked and old packs unlinked
33 defer_weaken($self, 'gcf');
39 my ($self, $check_only) = @_;
41 return eval { PublicInbox::Msgmap->new($self->{git_dir}) };
43 $self->{mm} ||= eval {
44 my $mm = PublicInbox::Msgmap->new($self->{git_dir});
46 # may be needed if we run low on handles
47 defer_weaken($self, 'mm');
54 $self->{search} ||= eval {
55 require PublicInbox::Search;
56 my $search = PublicInbox::Search->new($self->{git_dir});
58 # may be needed if we run low on handles
59 defer_weaken($self, 'search');
66 open my $fh, '<', "$self->{git_dir}/description" or return '';
67 my $desc = eval { local $/; <$fh> };
74 my ($self, $new) = @_;
75 $self->{address} = $new->{address};
76 $self->{domain} = $new->{domain};
77 if ($self->{git_dir} ne $new->{git_dir}) {
78 # new git_dir requires a new mm and gcf
79 $self->{mm} = $self->{gcf} = undef;
80 $self->{git_dir} = $new->{git_dir};