]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ExtSearchIdx.pm
inboxwritable: delay umask_prepare calls
[public-inbox.git] / lib / PublicInbox / ExtSearchIdx.pm
index c4b429df0cf8b5c8e71642d9e2d677837574d15e..c43a6c5e9fdca46342d5306ed48c14d95d309a0e 100644 (file)
@@ -30,13 +30,11 @@ use PublicInbox::V2Writable;
 use PublicInbox::InboxWritable;
 use PublicInbox::ContentHash qw(content_hash);
 use PublicInbox::Eml;
-use File::Spec;
 use PublicInbox::DS qw(now);
 use DBI qw(:sql_types); # SQL_BLOB
 
 sub new {
        my (undef, $dir, $opt) = @_;
-       $dir = File::Spec->canonpath($dir);
        my $l = $opt->{indexlevel} // 'full';
        $l !~ $PublicInbox::SearchIdx::INDEXLEVELS and
                die "invalid indexlevel=$l\n";
@@ -63,16 +61,23 @@ sub new {
 
 sub attach_inbox {
        my ($self, $ibx) = @_;
-       my $key = $ibx->eidx_key;
-       if (!$ibx->over || !$ibx->mm) {
-               warn "W: skipping $key (unindexed)\n";
-               return;
-       }
-       if (!defined($ibx->uidvalidity)) {
-               warn "W: skipping $key (no UIDVALIDITY)\n";
-               return;
+       my $ekey = $ibx->eidx_key;
+       my $misc = $self->{misc};
+       if ($misc && $misc->inbox_data($ibx)) { # all good if already indexed
+       } else {
+               my @sqlite = ($ibx->over, $ibx->mm);
+               my $uidvalidity = $ibx->uidvalidity;
+               $ibx->{mm} = $ibx->{over} = undef;
+               if (scalar(@sqlite) != 2) {
+                       warn "W: skipping $ekey (unindexed)\n";
+                       return;
+               }
+               if (!defined($uidvalidity)) {
+                       warn "W: skipping $ekey (no UIDVALIDITY)\n";
+                       return;
+               }
        }
-       $self->{ibx_map}->{$key} //= do {
+       $self->{ibx_map}->{$ekey} //= do {
                push @{$self->{ibx_list}}, $ibx;
                $ibx;
        }
@@ -929,7 +934,6 @@ sub idx_init { # similar to V2Writable
                PublicInbox::V2Writable::write_alternates($info_dir, $mode, $o);
        }
        $self->parallel_init($self->{indexlevel});
-       $self->umask_prepare;
        $self->with_umask(\&_idx_init, $self, $opt);
        $self->{oidx}->begin_lazy;
        $self->{oidx}->eidx_prep;
@@ -938,7 +942,6 @@ sub idx_init { # similar to V2Writable
 
 no warnings 'once';
 *done = \&PublicInbox::V2Writable::done;
-*umask_prepare = \&PublicInbox::InboxWritable::umask_prepare;
 *with_umask = \&PublicInbox::InboxWritable::with_umask;
 *parallel_init = \&PublicInbox::V2Writable::parallel_init;
 *nproc_shards = \&PublicInbox::V2Writable::nproc_shards;