From 1218bee34cf04498ac36add5c7e847698be541c2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 23 Jul 2021 10:56:11 +0000 Subject: lei: avoid SQLite COUNT() for dedupe 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. --- lib/PublicInbox/LeiSavedSearch.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/LeiSavedSearch.pm') diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index 929380ed..cfbf68c3 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -315,11 +315,11 @@ E: rename($dir_old, $dir_new) error: $! EOM } -# cf. LeiDedupe->dedupe_nr -sub dedupe_nr { +# cf. LeiDedupe->has_entries +sub has_entries { my $oidx = $_[0]->{oidx} // die 'BUG: no {oidx}'; - my @n = $oidx->{dbh}->selectrow_array('SELECT COUNT(*) FROM over'); - $n[0]; + my @n = $oidx->{dbh}->selectrow_array('SELECT num FROM over LIMIT 1'); + scalar(@n) ? 1 : undef; } no warnings 'once'; -- cgit v1.2.3-24-ge0c7