From 923e09d84e8eaa612c85f6d5ec57c3742390bebc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 29 Apr 2021 09:46:18 +0000 Subject: lei import: avoid IMAPTracker, use LeiMailSync more IMAPTracker has a UNIQUE constraint on the `url' column, which may cause compatibility and/or rollback problems in attempting to deal with UIDVALIDITY changes. Having multiple sources of truth leads to confusion and bugs, so relying on LeiMailSync exclusively ought to simplify things. Furthermore, since LeiMailSync is only written to by LeiStore, it is safer in that it won't mark a UID or article as imported until git-fast-import has seen it, and the SQLite commit always happens after "done\n" is sent to fast-import. This mostly reverts recent commits to IMAPTracker to support lei, those are: 1) commit 7632d8f7590daf70c65d4270e750c36552fa9389 ("net_reader: restart on first UID when UIDVALIDITY changes") 2) commit 311a5d37ad275cd75b1e64d87827c4d13fe4bfab ("imap_tracker: prepare for use with lei"). This means public-inbox-watch will not change between 1.6 and 1.7: -watch stops synching a folder when UIDVALIDITY changes. --- lib/PublicInbox/IMAPTracker.pm | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'lib/PublicInbox/IMAPTracker.pm') diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm index fe813582..5eb33cf7 100644 --- a/lib/PublicInbox/IMAPTracker.pm +++ b/lib/PublicInbox/IMAPTracker.pm @@ -39,20 +39,12 @@ sub dbh_new ($) { $dbh; } -sub get_last ($;$) { - my ($self, $validity) = @_; - my $sth; - if (defined $validity) { - $sth = $self->{dbh}->prepare_cached(<<'', undef, 1); -SELECT uid_validity, uid FROM imap_last WHERE url = ? AND uid_validity = ? - - $sth->execute($self->{url}, $validity); - } else { - $sth = $self->{dbh}->prepare_cached(<<'', undef, 1); +sub get_last ($) { + my ($self) = @_; + my $sth = $self->{dbh}->prepare_cached(<<'', undef, 1); SELECT uid_validity, uid FROM imap_last WHERE url = ? - $sth->execute($self->{url}); - } + $sth->execute($self->{url}); $sth->fetchrow_array; } @@ -70,19 +62,16 @@ VALUES (?, ?, ?) } sub new { - my ($class, $url, $dbname) = @_; + my ($class, $url) = @_; - unless (defined($dbname)) { - # original name for compatibility with old setups: - $dbname = PublicInbox::Config->config_dir() . '/imap.sqlite3'; + # original name for compatibility with old setups: + my $dbname = PublicInbox::Config->config_dir() . '/imap.sqlite3'; - # use the new XDG-compliant name for new setups: - if (!-f $dbname) { - $dbname = ($ENV{XDG_DATA_HOME} // - (($ENV{HOME} // '/nonexistent'). - '/.local/share')) . - '/public-inbox/imap.sqlite3'; - } + # use the new XDG-compliant name for new setups: + if (!-f $dbname) { + $dbname = ($ENV{XDG_DATA_HOME} // + (($ENV{HOME} // '/nonexistent').'/.local/share')) . + '/public-inbox/imap.sqlite3'; } if (!-f $dbname) { require File::Path; -- cgit v1.2.3-24-ge0c7