From e29e6dc98c5fb79484b7b9c5c07ebcfbe5b088dd Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 24 Oct 2021 19:36:43 -0700 Subject: [PATCH] sorted: make the in-memory implementation support Wiper So an in-memory key/value store can be used as an index, for the demo blob server on the website. --- pkg/sorted/mem.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/sorted/mem.go b/pkg/sorted/mem.go index 15e8578ce..e30b519af 100644 --- a/pkg/sorted/mem.go +++ b/pkg/sorted/mem.go @@ -31,10 +31,13 @@ import ( // NewMemoryKeyValue returns a KeyValue implementation that's backed only // by memory. It's mostly useful for tests and development. func NewMemoryKeyValue() KeyValue { - db := memdb.New(comparer.DefaultComparer, 128) - return &memKeys{db: db} + kv := new(memKeys) + kv.Wipe() + return kv } +var _ Wiper = (*memKeys)(nil) + // memKeys is a naive in-memory implementation of KeyValue for test & development // purposes only. type memKeys struct { @@ -42,6 +45,13 @@ type memKeys struct { db *memdb.DB } +func (s *memKeys) Wipe() error { + s.mu.Lock() + defer s.mu.Unlock() + s.db = memdb.New(comparer.DefaultComparer, 128) + return nil +} + // memIter converts from leveldb's iterator.Iterator interface, which // operates on []byte, to Perkeep's index.Iterator, which operates // on string.