]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ExtSearchIdx.pm
miscsearch: index UIDVALIDITY, use as startup cache
[public-inbox.git] / lib / PublicInbox / ExtSearchIdx.pm
index c6fb398beec13d90da2c9ba44a660ba343488682..9d64ff5a9a56c38b994f8a2da6cbc50829c9f837 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,21 +61,20 @@ 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 $ibxdir = File::Spec->canonpath($ibx->{inboxdir});
-       if ($ibxdir ne $ibx->{inboxdir}) {
-               warn "W: `$ibx->{inboxdir}' canonicalized to `$ibxdir'\n";
-               $ibx->{inboxdir} = $ibxdir;
+       my $ekey = $ibx->eidx_key;
+       my $misc = $self->{misc};
+       if ($misc && $misc->inbox_data($ibx)) { # all good if already indexed
+       } else {
+               if (!$ibx->over || !$ibx->mm) {
+                       warn "W: skipping $ekey (unindexed)\n";
+                       return;
+               }
+               if (!defined($ibx->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;
        }
@@ -530,8 +527,10 @@ sub host_ident () {
        state $retval = hostname . '-' . do {
                my $m; # machine-id(5) is systemd
                if (open(my $fh, '<', '/etc/machine-id')) { $m = <$fh> }
-               # hostid(1) is in GNU coreutils, kern.hostid is FreeBSD
-               chomp($m ||= `hostid` || `sysctl -n kern.hostid`);
+               # (g)hostid(1) is in GNU coreutils, kern.hostid is most BSDs
+               chomp($m ||= `{ sysctl -n kern.hostid ||
+                               hostid || ghostid; } 2>/dev/null`
+                       || "no-machine-id-or-hostid-on-$^O");
                $m;
        };
 }