- my ($self, $opts) = @_;
- delete $self->{lock_path} if $opts->{-skip_lock};
- $self->{ibx}->with_umask(\&_index_sync, $self, $opts);
-}
-
-sub too_big ($$) {
- my ($self, $oid) = @_;
- my $max_size = $self->{index_max_size} or return;
- my (undef, undef, $size) = $self->{ibx}->git->check($oid);
- die "E: bad $oid in $self->{ibx}->{inboxdir}\n" if !defined($size);
- return if $size <= $max_size;
- warn "W: skipping $oid ($size > $max_size)\n";
- 1;
+ my ($self, $opt) = @_;
+ delete $self->{lock_path} if $opt->{-skip_lock};
+ $self->with_umask(\&_index_sync, $self, $opt);
+ if ($opt->{reindex} && !$opt->{quit} &&
+ !grep(defined, @$opt{qw(since until)})) {
+ my %again = %$opt;
+ delete @again{qw(rethread reindex)};
+ index_sync($self, \%again);
+ $opt->{quit} = $again{quit}; # propagate to caller
+ }
+}
+
+sub check_size { # check_async cb for -index --max-size=...
+ my ($oid, $type, $size, $arg, $git) = @_;
+ (($type // '') eq 'blob') or die "E: bad $oid in $git->{git_dir}";
+ if ($size <= $arg->{max_size}) {
+ $git->cat_async($oid, $arg->{index_oid}, $arg);
+ } else {
+ warn "W: skipping $oid ($size > $arg->{max_size})\n";
+ }
+}
+
+sub v1_checkpoint ($$;$) {
+ my ($self, $sync, $stk) = @_;
+ $self->{ibx}->git->async_wait_all;
+
+ # $newest may be undef
+ my $newest = $stk ? $stk->{latest_cmt} : ${$sync->{latest_cmt}};
+ if (defined($newest)) {
+ my $cur = $self->{mm}->last_commit;
+ if (need_update($self, $sync, $cur, $newest)) {
+ $self->{mm}->last_commit($newest);
+ }
+ }
+ ${$sync->{max}} = $self->{batch_bytes};
+
+ $self->{mm}->{dbh}->commit;
+ eval { $self->{mm}->{dbh}->do('PRAGMA optimize') };
+ my $xdb = $self->{xdb};
+ if ($newest && $xdb) {
+ my $cur = $xdb->get_metadata('last_commit');
+ if (need_update($self, $sync, $cur, $newest)) {
+ $xdb->set_metadata('last_commit', $newest);
+ }
+ }
+ if ($stk) { # all done if $stk is passed
+ # let SearchView know a full --reindex was done so it can
+ # generate ->has_threadid-dependent links
+ if ($xdb && $sync->{reindex} && !ref($sync->{reindex})) {
+ my $n = $xdb->get_metadata('has_threadid');
+ $xdb->set_metadata('has_threadid', '1') if $n ne '1';
+ }
+ $self->{oidx}->rethread_done($sync->{-opt}); # all done
+ }
+ commit_txn_lazy($self);
+ $sync->{ibx}->git->cleanup;
+ my $nr = ${$sync->{nr}};
+ idx_release($self, $nr);
+ # let another process do some work...
+ if (my $pr = $sync->{-opt}->{-progress}) {
+ $pr->("indexed $nr/$sync->{ntodo}\n") if $nr;
+ }
+ if (!$stk && !$sync->{quit}) { # more to come
+ begin_txn_lazy($self);
+ $self->{mm}->{dbh}->begin_work;
+ }