]> Sergey Matveev's repositories - public-inbox.git/commitdiff
index: optimize after all SQLite DB commits
authorEric Wong <e@80x24.org>
Tue, 12 Oct 2021 22:44:58 +0000 (22:44 +0000)
committerEric Wong <e@80x24.org>
Wed, 13 Oct 2021 00:41:23 +0000 (00:41 +0000)
This covers v1 inboxes, as well.  We also guard the execution
since "PRAGMA optimize" was only introduced in SQLite 3.18.0
(2017-03-30)

lib/PublicInbox/LeiMailSync.pm
lib/PublicInbox/OverIdx.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm

index c6cd1bc58d0ae0b5d676b56288680f8dbb5c0eda..f7e37ad9ca808ce3b618d651366c3e2a0e28aeb3 100644 (file)
@@ -48,7 +48,7 @@ sub lms_pause {
        my ($self) = @_;
        $self->{fmap} = {};
        my $dbh = delete $self->{dbh};
-       $dbh->do('PRAGMA optimize') if $dbh;
+       eval { $dbh->do('PRAGMA optimize') } if $dbh;
 }
 
 sub create_tables {
index d6d706f7fed04363d409eb7aa34564f08ad7dc2e..9fdb26c0d5c2bef2417ce76cc5ee89a34bba8d20 100644 (file)
@@ -434,6 +434,7 @@ sub commit_lazy {
        my ($self) = @_;
        delete $self->{txn} or return;
        $self->{dbh}->commit;
+       eval { $self->{dbh}->do('PRAGMA optimize') };
 }
 
 sub begin_lazy {
index a2ed94993993ac6d03c5505bad916a5f192583a7..928152ec4df4ee83e773db9af38ab0c293ab58f2 100644 (file)
@@ -793,6 +793,7 @@ sub v1_checkpoint ($$;$) {
        ${$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');
index efcc1fc21a18e0a23ba26cf12311d7355220bd7f..3914383cc9d3deb239d3c88e3f19475439514576 100644 (file)
@@ -547,11 +547,11 @@ sub checkpoint ($;$) {
        }
        my $shards = $self->{idx_shards};
        if ($shards) {
-               my $mm = $self->{mm};
-               my $dbh = $mm->{dbh} if $mm;
+               my $dbh = $self->{mm}->{dbh} if $self->{mm};
 
                # SQLite msgmap data is second in importance
                $dbh->commit if $dbh;
+               eval { $dbh->do('PRAGMA optimize') };
 
                # SQLite overview is third
                $self->{oidx}->commit_lazy;
@@ -620,16 +620,10 @@ sub done {
                my $m = $err ? 'rollback' : 'commit';
                eval { $mm->{dbh}->$m };
                $err .= "msgmap $m: $@\n" if $@;
-               eval { $mm->{dbh}->do('PRAGMA optimize') };
-               $err .= "msgmap optimize: $@\n" if $@;
        }
-       if ($self->{oidx} && $self->{oidx}->{dbh}) {
-               if ($err) {
-                       eval { $self->{oidx}->rollback_lazy };
-                       $err .= "overview rollback: $@\n" if $@;
-               }
-               eval { $self->{oidx}->{dbh}->do('PRAGMA optimize') };
-               $err .= "overview optimize: $@\n" if $@;
+       if ($self->{oidx} && $self->{oidx}->{dbh} && $err) {
+               eval { $self->{oidx}->rollback_lazy };
+               $err .= "overview rollback: $@\n" if $@;
        }
 
        my $shards = delete $self->{idx_shards};