$dir;
}
-# 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;
-}
-
sub unconfigured_ibx ($$) {
my ($dir, $i) = @_;
my $name = "unconfigured-$i";
"$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;
}
# store 'indexlevel=medium' in v2 shard=0 and v1 (only one shard)
-# This metadata is read by Admin::detect_indexlevel:
+# This metadata is read by InboxWritable->detect_indexlevel:
sub set_metadata_once {
my ($self) = @_;
my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]);
my $watches = $ibx->{watch} or return;
+
+ $ibx->{indexlevel} //= $ibx->detect_indexlevel;
$watches = PublicInbox::Config::_array($watches);
for my $watch (@$watches) {
my $uri;
}
die "Only conversion from v1 inboxes is supported\n" if $old->version >= 2;
-my $detected = PublicInbox::Admin::detect_indexlevel($old);
+my $detected = $old->detect_indexlevel;
$old->{indexlevel} //= $detected;
my $env;
if ($opt->{'index'}) {
my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
PublicInbox::Admin::require_or_die('-index');
unless (@ibxs) { print STDERR $help; exit 1 }
+require PublicInbox::InboxWritable;
my (@eidx, %eidx_seen);
my $update_extindex = $opt->{'update-extindex'};
my $mods = {};
my @eidx_unconfigured;
foreach my $ibx (@ibxs) {
+ $ibx = PublicInbox::InboxWritable->new($ibx);
# detect_indexlevel may also set $ibx->{-skip_docdata}
- my $detected = PublicInbox::Admin::detect_indexlevel($ibx);
+ my $detected = $ibx->detect_indexlevel;
# XXX: users can shoot themselves in the foot, with opt->{indexlevel}
$ibx->{indexlevel} //= $opt->{indexlevel} // ($opt->{xapian_only} ?
'full' : $detected);
PublicInbox::Admin::require_or_die(keys %$mods);
my $env = PublicInbox::Admin::index_prepare($opt, $cfg);
local %ENV = (%ENV, %$env) if $env;
-require PublicInbox::InboxWritable;
PublicInbox::Xapcmd::check_compact() if $opt->{compact};
PublicInbox::Admin::progress_prepare($opt);
for my $ibx (@ibxs) {
- $ibx = PublicInbox::InboxWritable->new($ibx);
if ($opt->{compact} >= 2) {
PublicInbox::Xapcmd::run($ibx, 'compact', $opt->{compact_opt});
}
use PublicInbox::Admin;
use PublicInbox::Import;
use File::Path qw(remove_tree);
+require PublicInbox::InboxWritable;
require_mods(qw(DBD::SQLite Search::Xapian));
use_ok 'PublicInbox::Over';
{
my $cfg = PublicInbox::Config->new;
my $ibx = $cfg->lookup($addr);
- my $lvl = PublicInbox::Admin::detect_indexlevel($ibx);
+ my $lvl = PublicInbox::InboxWritable::detect_indexlevel($ibx);
is($lvl, 'medium', 'indexlevel detected');
is($ibx->{-skip_docdata}, 1, '--skip-docdata flag set on -index');
$smsg = $ibx->over->get_art(1);
my $check_v2 = sub {
my $ibx = PublicInbox::Inbox->new({inboxdir => $v2dir,
address => $addr});
- my $lvl = PublicInbox::Admin::detect_indexlevel($ibx);
+ my $lvl = PublicInbox::InboxWritable::detect_indexlevel($ibx);
is($lvl, 'medium', 'indexlevel detected after convert');
is($ibx->{-skip_docdata}, 1,
'--skip-docdata preserved after convert');
use v5.10.1;
use PublicInbox::TestCommon;
use PublicInbox::Eml;
-use PublicInbox::Inbox;
+use PublicInbox::InboxWritable;
require PublicInbox::Admin;
my $PI_TEST_VERSION = $ENV{PI_TEST_VERSION} || 2;
require_git('2.6') if $PI_TEST_VERSION == 2;
if ($level ne 'basic') {
ok(run_script(['-xcpdb', '-q', $mirror]), "v$v xcpdb OK");
- is(PublicInbox::Admin::detect_indexlevel($ro_mirror), $level,
+ is(PublicInbox::InboxWritable::detect_indexlevel($ro_mirror),
+ $level,
'indexlevel detectable by Admin after xcpdb v' .$v.$level);
delete $ro_mirror->{$_} for (qw(over search));
my $mset = $ro_mirror->search->mset('m:m@2');
is_deeply(\@rw_nums, \@expect, "v$v master has expected NNTP articles");
is_deeply(\@ro_nums, \@expect, "v$v mirror matches master articles");
- is(PublicInbox::Admin::detect_indexlevel($ro_mirror), $level,
+ is(PublicInbox::InboxWritable::detect_indexlevel($ro_mirror), $level,
'indexlevel detectable by Admin '.$v.$level);
SKIP: {
use PublicInbox::Config;
use PublicInbox::TestCommon;
use PublicInbox::Admin;
+use PublicInbox::InboxWritable;
my ($tmpdir, $for_destroy) = tmpdir();
sub quiet_fail {
my ($cmd, $msg) = @_;
ok(run_script($cmd), "-init -L $lvl");
is(read_indexlevel("v2$lvl"), $lvl, "indexlevel set to '$lvl'");
my $ibx = PublicInbox::Inbox->new({ inboxdir => $dir });
- is(PublicInbox::Admin::detect_indexlevel($ibx), $lvl,
+ is(PublicInbox::InboxWritable::detect_indexlevel($ibx), $lvl,
'detected expected level w/o config');
ok(!$ibx->{-skip_docdata}, 'docdata written by default');
}
"$name\@example.com" ];
ok(run_script($cmd), "-init -V$v --skip-docdata");
my $ibx = PublicInbox::Inbox->new({ inboxdir => $dir });
- is(PublicInbox::Admin::detect_indexlevel($ibx), 'full',
+ is(PublicInbox::InboxWritable::detect_indexlevel($ibx), 'full',
"detected default indexlevel -V$v");
ok($ibx->{-skip_docdata}, "docdata skip set -V$v");
ok($ibx->search->has_threadid, 'has_threadid flag set on new inbox');