about summary refs log tree commit homepage
path: root/lib/PublicInbox/InboxWritable.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-04-06 12:39:52 +0000
committerEric Wong <e@80x24.org>2023-04-06 21:20:50 +0000
commit51a786f7215a2b84114c76fbd6589a55c198af65 (patch)
treed46f60b2793c2de69fc7dc583f10a3e079562aeb /lib/PublicInbox/InboxWritable.pm
parentc32cb39ce267f684c1171bf42e879f797c40e79f (diff)
downloadpublic-inbox-51a786f7215a2b84114c76fbd6589a55c198af65.tar.gz
I favor leaving the publicinbox.<name>.indexlevel parameter
out of config files to make it easier to alter and reduce
sources of truth.  It worked well in most cases, but
public-inbox-watch also needs to detect the indexlevel.

Moving the sub to InboxWritable (from Admin) probably makes
sense since it's a per-inbox attribute and allows -watch
to reuse it.
Diffstat (limited to 'lib/PublicInbox/InboxWritable.pm')
-rw-r--r--lib/PublicInbox/InboxWritable.pm27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 17dfbe18..022e2a69 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -245,4 +245,31 @@ sub git_dir_latest {
                 "$self->{inboxdir}/git/$$max.git" : undef;
 }
 
+# for unconfigured inboxes
+sub detect_indexlevel ($) {
+        my ($ibx) = @_;
+
+        my $over = $ibx->over;
+        my $srch = $ibx->search;
+        delete @$ibx{qw(over search)}; # don't leave open FDs lying around
+
+        # brand new or never before indexed inboxes default to full
+        return 'full' unless $over;
+        my $l = 'basic';
+        return $l unless $srch;
+        if (my $xdb = $srch->xdb) {
+                $l = 'full';
+                my $m = $xdb->get_metadata('indexlevel');
+                if ($m eq 'medium') {
+                        $l = $m;
+                } elsif ($m ne '') {
+                        warn <<"";
+$ibx->{inboxdir} has unexpected indexlevel in Xapian: $m
+
+                }
+                $ibx->{-skip_docdata} = 1 if $xdb->get_metadata('skip_docdata');
+        }
+        $l;
+}
+
 1;