]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Over.pm
lei import: speed up kw updates for old IMAP messages
[public-inbox.git] / lib / PublicInbox / Over.pm
index 06ea439d484f78bbd51350b6ce490f9b0ec43967..58fdea0e197ce4c54364a0e45befc89560284f6a 100644 (file)
@@ -7,7 +7,7 @@
 package PublicInbox::Over;
 use strict;
 use v5.10.1;
-use DBI;
+use DBI qw(:sql_types); # SQL_BLOB
 use DBD::SQLite;
 use PublicInbox::Smsg;
 use Compress::Zlib qw(uncompress);
@@ -349,4 +349,26 @@ sub check_inodes {
        }
 }
 
+sub oidbin_exists {
+       my ($self, $oidbin) = @_;
+       if (wantarray) {
+               my $sth = $self->dbh->prepare_cached(<<'', undef, 1);
+SELECT docid FROM xref3 WHERE oidbin = ? ORDER BY docid ASC
+
+               $sth->bind_param(1, $oidbin, SQL_BLOB);
+               $sth->execute;
+               my $tmp = $sth->fetchall_arrayref;
+               map { $_->[0] } @$tmp;
+       } else {
+               my $sth = $self->dbh->prepare_cached(<<'', undef, 1);
+SELECT COUNT(*) FROM xref3 WHERE oidbin = ?
+
+               $sth->bind_param(1, $oidbin, SQL_BLOB);
+               $sth->execute;
+               $sth->fetchrow_array;
+       }
+}
+
+sub blob_exists { oidbin_exists($_[0], pack('H*', $_[1])) }
+
 1;