- my $max = $opt->{jobs} || scalar(@q);
- $ibx->with_umask(sub {
- my $im = $ibx->importer(0);
- $im->lock_acquire;
-
- # fine-grained locking if we prepare for reindex
- if (!$opt->{-coarse_lock}) {
- prepare_reindex($ibx, $im, $reindex);
- $im->lock_release;
- }
+ ($tmp, \@queue);
+}
+
+sub check_compact () { runnable_or_die($XAPIAN_COMPACT) }
+
+sub _run {
+ my ($ibx, $cb, $opt) = @_;
+ my $im = $ibx->importer(0);
+ $im->lock_acquire;
+ my ($tmp, $queue) = prepare_run($ibx, $opt);
+
+ # fine-grained locking if we prepare for reindex
+ if (!$opt->{-coarse_lock}) {
+ prepare_reindex($ibx, $im, $opt);
+ $im->lock_release;
+ }
+
+ $ibx->cleanup;
+ process_queue($queue, $cb, $opt);
+ $im->lock_acquire if !$opt->{-coarse_lock};
+ commit_changes($ibx, $im, $tmp, $opt);
+}
+
+sub run {
+ my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact'
+ my $cb = \&$task;
+ PublicInbox::Admin::progress_prepare($opt ||= {});
+ defined(my $dir = $ibx->{inboxdir}) or die "no inboxdir defined\n";
+ -d $dir or die "inboxdir=$dir does not exist\n";
+ check_compact() if $opt->{compact} && $ibx->search;
+
+ if (!$opt->{-coarse_lock}) {
+ # per-epoch ranges for v2
+ # v1:{ from => $OID }, v2:{ from => [ $OID, $OID, $OID ] } }
+ $opt->{reindex} = { from => $ibx->version == 1 ? '' : [] };
+ PublicInbox::SearchIdx::load_xapian_writable();
+ }