+sub v1_checkpoint ($$;$) {
+ my ($self, $sync, $stk) = @_;
+ $self->{ibx}->git->check_async_wait;
+ $self->{ibx}->git->cat_async_wait;
+
+ # latest_cmt may be undef
+ my $newest = $stk ? $stk->{latest_cmt} : undef;
+ if ($newest) {
+ my $cur = $self->{mm}->last_commit || '';
+ if (need_update($self, $cur, $newest)) {
+ $self->{mm}->last_commit($newest);
+ }
+ } else {
+ ${$sync->{max}} = $self->{batch_bytes};
+ }
+
+ $self->{mm}->{dbh}->commit;
+ if ($newest && need_xapian($self)) {
+ my $xdb = $self->{xdb};
+ my $cur = $xdb->get_metadata('last_commit');
+ if (need_update($self, $cur, $newest)) {
+ $xdb->set_metadata('last_commit', $newest);
+ }
+
+ # let SearchView know a full --reindex was done so it can
+ # generate ->has_threadid-dependent links
+ if ($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}) if $newest; # all done
+ commit_txn_lazy($self);
+ $self->{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) { # more to come
+ begin_txn_lazy($self);
+ $self->{mm}->{dbh}->begin_work;