X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FIMAPTracker.pm;h=4efa8a7e7e38b774ee09709b1de027d7c4cd8b79;hb=refs%2Fheads%2Fmaster;hp=102a74ce66b8ec0c1ba52be5200ee37d38dd08de;hpb=35e31227139e401cf7845d824a1b4e6a1de56fe3;p=public-inbox.git
diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm
index 102a74ce..4efa8a7e 100644
--- a/lib/PublicInbox/IMAPTracker.pm
+++ b/lib/PublicInbox/IMAPTracker.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
package PublicInbox::IMAPTracker;
use strict;
@@ -29,7 +29,12 @@ sub dbh_new ($) {
sqlite_use_immediate_transaction => 1,
});
$dbh->{sqlite_unicode} = 1;
- $dbh->do('PRAGMA journal_mode = TRUNCATE');
+
+ # TRUNCATE reduces I/O compared to the default (DELETE).
+ # Allow and preserve user-overridden WAL, but don't force it.
+ my $jm = $dbh->selectrow_array('PRAGMA journal_mode');
+ $dbh->do('PRAGMA journal_mode = TRUNCATE') if $jm ne 'wal';
+
create_tables($dbh);
$dbh;
}
@@ -44,13 +49,14 @@ SELECT uid_validity, uid FROM imap_last WHERE url = ?
}
sub update_last ($$$) {
- my ($self, $validity, $last) = @_;
+ my ($self, $validity, $last_uid) = @_;
+ return unless defined $last_uid;
my $sth = $self->{dbh}->prepare_cached(<<'');
INSERT OR REPLACE INTO imap_last (url, uid_validity, uid)
VALUES (?, ?, ?)
$self->lock_acquire;
- my $rv = $sth->execute($self->{url}, $validity, $last);
+ my $rv = $sth->execute($self->{url}, $validity, $last_uid);
$self->lock_release;
$rv;
}
@@ -59,7 +65,7 @@ sub new {
my ($class, $url) = @_;
# original name for compatibility with old setups:
- my $dbname = PublicInbox::Config->config_dir() . "/imap.sqlite3";
+ my $dbname = PublicInbox::Config->config_dir() . '/imap.sqlite3';
# use the new XDG-compliant name for new setups:
if (!-f $dbname) {
@@ -69,8 +75,11 @@ sub new {
}
if (!-f $dbname) {
require File::Path;
- require File::Basename;
- File::Path::mkpath(File::Basename::dirname($dbname));
+ require PublicInbox::Syscall;
+ my ($dir) = ($dbname =~ m!(.*?/)[^/]+\z!);
+ File::Path::mkpath($dir);
+ PublicInbox::Syscall::nodatacow_dir($dir);
+ open my $fh, '+>>', $dbname or die "failed to open $dbname: $!";
}
my $self = bless { lock_path => "$dbname.lock", url => $url }, $class;
$self->lock_acquire;