]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Over.pm
imap: STATUS/EXAMINE: rely on SQLite overview
[public-inbox.git] / lib / PublicInbox / Over.pm
index 1faeff418f4d9caadc30eb6e6c9d19541b246caf..e0f20ea6d3da2de5a1e92cdd84fee2e66e68e4bd 100644 (file)
@@ -229,4 +229,34 @@ sub uid_range {
        $dbh->selectcol_arrayref($q, undef, $beg, $end);
 }
 
+sub max {
+       my ($self) = @_;
+       my $sth = $self->connect->prepare_cached(<<'', undef, 1);
+SELECT MAX(num) FROM over WHERE num > 0
+
+       $sth->execute;
+       $sth->fetchrow_array // 0;
+}
+
+sub imap_status {
+       my ($self, $uid_base, $uid_end) = @_;
+       my $dbh = $self->connect;
+       my $sth = $dbh->prepare_cached(<<'', undef, 1);
+SELECT COUNT(num) FROM over WHERE num > ? AND num <= ?
+
+       $sth->execute($uid_base, $uid_end);
+       my $exists = $sth->fetchrow_array;
+
+       $sth = $dbh->prepare_cached(<<'', undef, 1);
+SELECT MAX(num) + 1 FROM over WHERE num <= ?
+
+       $sth->execute($uid_end);
+       my $uidnext = $sth->fetchrow_array;
+
+       $sth = $dbh->prepare_cached(<<'', undef, 1);
+SELECT MAX(num) FROM over WHERE num > 0
+
+       ($exists, $uidnext, $sth->fetchrow_array // 0);
+}
+
 1;