about summary refs log tree commit homepage
path: root/lib/PublicInbox/SharedKV.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-07-23 10:56:11 +0000
committerEric Wong <e@80x24.org>2021-07-25 00:11:36 +0000
commit1218bee34cf04498ac36add5c7e847698be541c2 (patch)
tree142afb972faffd2f01c1369cd1858cf36eb5b8ea /lib/PublicInbox/SharedKV.pm
parentd15bd6a20a836473479d8431682ba305e2dcdfbe (diff)
downloadpublic-inbox-1218bee34cf04498ac36add5c7e847698be541c2.tar.gz
SQLite COUNT() is a slow operation that does a full table scan
with no conditions.  There's no need for it, since lei dedupe
only needs to know if it's empty or not to decide between
new/ and cur/ for Maildir outputs.
Diffstat (limited to 'lib/PublicInbox/SharedKV.pm')
-rw-r--r--lib/PublicInbox/SharedKV.pm7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/PublicInbox/SharedKV.pm b/lib/PublicInbox/SharedKV.pm
index 8347b195..3487e820 100644
--- a/lib/PublicInbox/SharedKV.pm
+++ b/lib/PublicInbox/SharedKV.pm
@@ -154,6 +154,13 @@ SELECT COUNT(k) FROM kv
         $sth->fetchrow_array;
 }
 
+# faster than ->count due to how SQLite works
+sub has_entries {
+        my ($self) = @_;
+        my @n = $self->{dbh}->selectrow_array('SELECT k FROM kv LIMIT 1');
+        scalar(@n) ? 1 : undef;
+}
+
 sub dbh_release {
         my ($self, $lock) = @_;
         my $dbh = delete $self->{dbh} or return;