From 7632d8f7590daf70c65d4270e750c36552fa9389 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 23 Apr 2021 07:28:15 +0000 Subject: net_reader: restart on first UID when UIDVALIDITY changes In other words, treat the same IMAP folder with a different UIDVALIDITY as a completely different folder. If the UIDVALIDITY changes, we can start from UID=1 without falling behind or losing data. If the UIDVALIDITY gets reset to a previously known-good message, we can still resume where we left off before the first UIDVALIDITY change. This affects public-inbox-watch and "lei import" One potential downside of this is for rare altid users, but that's mainly intended for NNTP article numbers which are/were often publicized; not IMAP UIDs which are rarely publicized. The other potential downside is bandwidth waste in in the rare case UIDVALIDITY changes while IMAP folder contents remain unchanged. There's no extra storage used due to existing (v1|v2|lei/store) deduplication mechanisms. Before this change, we were matching offlineimap behavior and stopped synching an IMAP folder when its UIDVALIDITY changed. offlineimap behavior made sense for IMAP <=> Maildir synchronization since Maildirs had no sense of UIDVALIDITY and could only rely on name mapping. --- lib/PublicInbox/IMAPTracker.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/IMAPTracker.pm') diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm index bcf7af2e..fe813582 100644 --- a/lib/PublicInbox/IMAPTracker.pm +++ b/lib/PublicInbox/IMAPTracker.pm @@ -39,12 +39,20 @@ sub dbh_new ($) { $dbh; } -sub get_last ($) { - my ($self) = @_; - my $sth = $self->{dbh}->prepare_cached(<<'', undef, 1); +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); SELECT uid_validity, uid FROM imap_last WHERE url = ? - $sth->execute($self->{url}); + $sth->execute($self->{url}); + } $sth->fetchrow_array; } -- cgit v1.2.3-24-ge0c7