]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMailSync.pm
index: optimize after all SQLite DB commits
[public-inbox.git] / lib / PublicInbox / LeiMailSync.pm
index 522a5ebc865e3e3a6b0e5b89e83f91d72eb226ac..f7e37ad9ca808ce3b618d651366c3e2a0e28aeb3 100644 (file)
@@ -47,7 +47,8 @@ sub lms_write_prepare { ($_[0]->{dbh} //= dbh_new($_[0], 1)); $_[0] }
 sub lms_pause {
        my ($self) = @_;
        $self->{fmap} = {};
-       delete $self->{dbh};
+       my $dbh = delete $self->{dbh};
+       eval { $dbh->do('PRAGMA optimize') } if $dbh;
 }
 
 sub create_tables {
@@ -299,16 +300,19 @@ sub locations_for {
 
 # returns a list of folders used for completion
 sub folders {
-       my ($self, $pfx) = @_;
-       my $dbh = $self->{dbh} //= dbh_new($self);
+       my ($self, @pfx) = @_;
        my $sql = 'SELECT loc FROM folders';
-       my @pfx;
-       if (defined $pfx) {
+       if (defined($pfx[0])) {
                $sql .= ' WHERE loc LIKE ? ESCAPE ?';
-               @pfx = ($pfx, '\\');
+               my $anywhere = !!$pfx[1];
+               $pfx[1] = '\\';
                $pfx[0] =~ s/([%_\\])/\\$1/g; # glob chars
                $pfx[0] .= '%';
+               substr($pfx[0], 0, 0, '%') if $anywhere;
+       } else {
+               @pfx = (); # [0] may've been undef
        }
+       my $dbh = $self->{dbh} //= dbh_new($self);
        map { $_->[0] } @{$dbh->selectall_arrayref($sql, undef, @pfx)};
 }