]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMailSync.pm
lei import: speed up kw updates for old IMAP messages
[public-inbox.git] / lib / PublicInbox / LeiMailSync.pm
index c7f78239e7e50c5101ed943d7be3b2f316eb8782..75603d89e1788127487e83a5b396b882d60ba8c1 100644 (file)
@@ -54,6 +54,10 @@ CREATE TABLE IF NOT EXISTS blob2num (
        UNIQUE (oidbin, fid, uid)
 )
 
+       # speeds up LeiImport->ck_update_kw (for "lei import") by 5-6x:
+       $dbh->do(<<'');
+CREATE INDEX IF NOT EXISTS idx_fid_uid ON blob2num(fid,uid)
+
        $dbh->do(<<'');
 CREATE TABLE IF NOT EXISTS blob2name (
        oidbin VARBINARY NOT NULL,
@@ -361,6 +365,16 @@ sub forget_folder {
        $dbh->do('DELETE FROM folders WHERE fid = ?', undef, $fid);
 }
 
+sub imap_oidbin ($$$) {
+       my ($self, $url, $uid) = @_; # $url MUST have UIDVALIDITY
+       my $fid = $self->{fmap}->{$url} //= fid_for($self, $url) // return;
+       my $sth = $self->{dbh}->prepare_cached(<<EOM, undef, 1);
+SELECT oidbin FROM blob2num WHERE fid = ? AND uid = ?
+EOM
+       $sth->execute($fid, $uid);
+       $sth->fetchrow_array;
+}
+
 sub imap_oid {
        my ($self, $lei, $uid_uri) = @_;
        my $mailbox_uri = $uid_uri->clone;
@@ -373,13 +387,7 @@ sub imap_oid {
                }
                $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
        }
-       my $fid = $self->{fmap}->{$folders->[0]} //=
-               fid_for($self, $folders->[0]) // return;
-       my $sth = $self->{dbh}->prepare_cached(<<EOM, undef, 1);
-SELECT oidbin FROM blob2num WHERE fid = ? AND uid = ?
-EOM
-       $sth->execute($fid, $uid_uri->uid);
-       my ($oidbin) = $sth->fetchrow_array;
+       my $oidbin = imap_oidbin($self, $folders->[0], $uid_uri->uid);
        $oidbin ? unpack('H*', $oidbin) : undef;
 }
 
@@ -387,10 +395,11 @@ EOM
 # warnings, not sure what...
 sub DESTROY {
        my ($self) = @_;
-       my $dbh = $self->{dbh} or return;
+       my $dbh = delete($self->{dbh}) or return;
        return if $dbh->{ReadOnly};
        use Carp;
-       warn "BUG $$ $0 $self {dbh} UNCOMMITTED ", Carp::longmess();
+       undef $dbh;
+       warn "BUG $$ $0 $self {dbh} OPEN ppid=".getppid.' '.Carp::longmess();
 }
 
 1;