]> Sergey Matveev's repositories - public-inbox.git/commitdiff
search: avoid setting undef hashtable entries
authorEric Wong <e@80x24.org>
Sat, 25 Sep 2021 22:16:45 +0000 (22:16 +0000)
committerEric Wong <e@80x24.org>
Sun, 26 Sep 2021 00:06:26 +0000 (00:06 +0000)
`undef' entries still take up a slot in the hash table, and
cause the `exists' check to false-positive in ->cleanup_shards.
This should fully fix the (innocuous) messages introduced in
commit 63d7b8ce (daemons: revamp periodic cleanup task, 2021-09-23)

lib/PublicInbox/AdminEdit.pm
lib/PublicInbox/Inbox.pm
lib/PublicInbox/Search.pm

index 2f6707d8b09ab309bb9be8841ada69b6da585ec4..c8c3d3e8aeb44aae4c1202c273465fe9100d3267 100644 (file)
@@ -27,8 +27,9 @@ sub check_editable ($) {
                # Make sure it's purged in that case:
                $ibx->over or die "no over.sqlite3 in $ibx->{inboxdir}\n";
 
-               # $ibx->{search} is populated by $ibx->over call
-               my $xdir_ro = $ibx->{search}->xdir(1);
+               require PublicInbox::Search;
+               my $xdir_ro = PublicInbox::Search->new($ibx)->xdir(1);
+
                my $nshard = 0;
                foreach my $shard (<$xdir_ro/*>) {
                        if (-d $shard && $shard =~ m!/[0-9]+\z!) {
index c0962af9864411970c9c9f16f5f35076548d19b6..3ba92c997f2c669911e4f6667f5576ff1cd4c613 100644 (file)
@@ -167,12 +167,12 @@ sub mm {
 
 sub search {
        my ($self) = @_;
-       my $srch = $self->{search} //= eval {
+       $self->{search} // eval {
                _cleanup_later($self);
                require PublicInbox::Search;
-               PublicInbox::Search->new($self);
+               my $srch = PublicInbox::Search->new($self);
+               (eval { $srch->xdb }) ? ($self->{search} = $srch) : undef;
        };
-       (eval { $srch->xdb }) ? $srch : undef;
 }
 
 # isrch is preferred for read-only interfaces if available since it
@@ -181,15 +181,14 @@ sub isrch { $_[0]->{isrch} // search($_[0]) }
 
 sub over {
        my ($self, $req) = @_;
-       $self->{over} //= eval {
-               my $srch = $self->{search} //= do {
-                       _cleanup_later($self);
+       $self->{over} // eval {
+               my $srch = $self->{search} // do {
                        require PublicInbox::Search;
                        PublicInbox::Search->new($self);
                };
                my $over = PublicInbox::Over->new("$srch->{xpfx}/over.sqlite3");
                $over->dbh; # may fail
-               $over;
+               $self->{over} = $over;
        } // ($req ? croak("E: $@") : undef);
 }
 
@@ -293,7 +292,7 @@ sub imap_url { $_[0]->{-imap_url} //= _x_url($_[0], 'imap', $_[1]) }
 sub nntp_usable {
        my ($self) = @_;
        my $ret = mm($self) && over($self);
-       $self->{mm} = $self->{over} = $self->{search} = undef;
+       delete @$self{qw(mm over search)};
        $ret;
 }
 
index d285c11cf07058051202c7bda48a6cb7f66a7b87..17e202e1da8300c5e7927ca4322f2c49bf4a5cb8 100644 (file)
@@ -234,12 +234,12 @@ sub mset_to_artnums {
 
 sub xdb ($) {
        my ($self) = @_;
-       $self->{xdb} //= do {
+       $self->{xdb} // do {
                my @xdb = $self->xdb_shards_flat or return;
                $self->{nshard} = scalar(@xdb);
                my $xdb = shift @xdb;
                $xdb->add_database($_) for @xdb;
-               $xdb;
+               $self->{xdb} = $xdb;
        };
 }
 
@@ -261,10 +261,10 @@ sub new {
        my ($class, $ibx) = @_;
        ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
        my $xap = $ibx->version > 1 ? 'xap' : 'public-inbox/xapian';
-       bless {
-               xpfx => "$ibx->{inboxdir}/$xap" . SCHEMA_VERSION,
-               altid => $ibx->{altid},
-       }, $class;
+       my $xpfx = "$ibx->{inboxdir}/$xap".SCHEMA_VERSION;
+       my $self = bless { xpfx => $xpfx }, $class;
+       $self->{altid} = $ibx->{altid} if defined($ibx->{altid});
+       $self;
 }
 
 sub reopen {