]> Sergey Matveev's repositories - public-inbox.git/commitdiff
sharedkv: split out index_values
authorEric Wong <e@80x24.org>
Thu, 31 Dec 2020 13:51:24 +0000 (13:51 +0000)
committerEric Wong <e@80x24.org>
Fri, 1 Jan 2021 05:00:38 +0000 (05:00 +0000)
In most cases, we won't need to index by value, so
don't waste cycles or space on it.

lib/PublicInbox/SharedKV.pm
t/shared_kv.t

index 52a7424eb19fe8a733c153b2ca94988942f84165..983952f59a961a08867aa25bed5f55543d00ba01 100644 (file)
@@ -36,7 +36,6 @@ CREATE TABLE IF NOT EXISTS kv (
        UNIQUE (k)
 )
 
-               $dbh->do('CREATE INDEX IF NOT EXISTS idx_v ON kv (v)');
                $dbh;
        }
 }
@@ -59,6 +58,12 @@ sub new {
        $self;
 }
 
+sub index_values {
+       my ($self) = @_;
+       my $lock = $self->lock_for_scope;
+       $self->dbh($lock)->do('CREATE INDEX IF NOT EXISTS idx_v ON kv (v)');
+}
+
 sub set_maybe {
        my ($self, $key, $val, $lock) = @_;
        $lock //= $self->lock_for_scope;
index 4b72746238407c493075b94a6e899fd41aa14b0f..ad901328360bfa3e755cd7d2d951eb2dfbbd700c 100644 (file)
@@ -26,6 +26,7 @@ is($skv->get($dead), $cafe, 'get after xchg');
 is($skv->xchg($dead, undef), $cafe, 'xchg to undef');
 is($skv->get($dead), undef, 'get after xchg to undef');
 is($skv->get($cafe), $dead, 'get after set_maybe');
+ok($skv->index_values, 'index_values works');
 is($skv->replace_values($dead, $cafe), 1, 'replaced one by value');
 is($skv->get($cafe), $cafe, 'value updated');
 is($skv->replace_values($dead, $cafe), 0, 'replaced none by value');