about summary refs log tree commit homepage
path: root/lib/PublicInbox/Msgmap.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-07-24 05:56:02 +0000
committerEric Wong <e@yhbt.net>2020-07-25 20:48:18 +0000
commit0e68dbad3dc5e3fbc44e8ba8be576b81455d3359 (patch)
treedfe57fccc97fdf43ce68f3ae6f5cc804a00520df /lib/PublicInbox/Msgmap.pm
parentde8e1586d732ae6c09a92588a8e4d442aedbff37 (diff)
downloadpublic-inbox-0e68dbad3dc5e3fbc44e8ba8be576b81455d3359.tar.gz
This allows us to speed up indexing operations to SQLite
and Xapian.

Unfortunately, it doesn't affect operations using
`xapian-compact' and the compactor API, since that doesn't seem
to support Xapian::DB_NO_SYNC, yet.
Diffstat (limited to 'lib/PublicInbox/Msgmap.pm')
-rw-r--r--lib/PublicInbox/Msgmap.pm21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 9d2ef0dc..839ddf7c 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -32,12 +32,11 @@ sub new_file {
         my $self = bless { filename => $f }, $class;
         my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, $rw);
         if ($rw) {
-                create_tables($dbh);
-
                 # TRUNCATE reduces I/O compared to the default (DELETE)
                 $dbh->do('PRAGMA journal_mode = TRUNCATE');
 
                 $dbh->begin_work;
+                create_tables($dbh);
                 $self->created_at(time) unless $self->created_at;
 
                 my $max = $self->max // 0;
@@ -51,12 +50,17 @@ sub new_file {
 sub tmp_clone {
         my ($self) = @_;
         my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, TMPDIR => 1);
-        $self->{dbh}->sqlite_backup_to_file($fn);
-        my $tmp = ref($self)->new_file($fn, 1);
-        $tmp->{dbh}->do('PRAGMA synchronous = OFF');
-        $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
+        my $tmp;
+        if ($self->{dbh}->can('sqlite_backup_to_dbh')) {
+                $tmp = ref($self)->new_file($fn, 2);
+                $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
+                $self->{dbh}->sqlite_backup_to_dbh($tmp->{dbh});
+        } else { # DBD::SQLite <= 1.61_01
+                $self->{dbh}->sqlite_backup_to_file($fn);
+                $tmp = ref($self)->new_file($fn, 2);
+                $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY');
+        }
         $tmp->{pid} = $$;
-        close $fh or die "failed to close $fn: $!";
         $tmp;
 }
 
@@ -241,8 +245,7 @@ sub atfork_parent {
         $self->{pid} or die 'BUG: not a temporary clone';
         $self->{dbh} and die 'BUG: tmp_clone dbh not prepared for parent';
         defined($self->{filename}) or die 'BUG: {filename} not defined';
-        my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, 1);
-        $dbh->do('PRAGMA synchronous = OFF');
+        $self->{dbh} = PublicInbox::Over::dbh_new($self, 2);
 }
 
 sub atfork_prepare {