From 87c5c4297284791ca60ee9eccc4d685b05013272 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Wed, 1 Mar 2023 09:44:54 +0000 Subject: [chore/performance] simplify storage driver to use storage.Storage directly (#1576) * simply use storage.Storage, removing wrapping KVStore as we don't need KV store locking functionality Signed-off-by: kim * fix missing unwrapped function Signed-off-by: kim * add code comment Signed-off-by: kim * linter, please take my offering in peace Signed-off-by: kim --------- Signed-off-by: kim --- testrig/storage.go | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'testrig/storage.go') diff --git a/testrig/storage.go b/testrig/storage.go index 5694b3ab6..4bbf02696 100644 --- a/testrig/storage.go +++ b/testrig/storage.go @@ -24,7 +24,6 @@ import ( "os" "path" - "codeberg.org/gruf/go-store/v2/kv" "codeberg.org/gruf/go-store/v2/storage" gtsstorage "github.com/superseriousbusiness/gotosocial/internal/storage" ) @@ -33,7 +32,6 @@ import ( func NewInMemoryStorage() *gtsstorage.Driver { storage := storage.OpenMemory(200, false) return >sstorage.Driver{ - KVStore: kv.New(storage), Storage: storage, } } @@ -95,30 +93,18 @@ func StandardStorageSetup(storage *gtsstorage.Driver, relativePath string) { } } -// StandardStorageTeardown deletes everything in storage so that it's clean for -// the next test -// nolint:gocritic // complains about the type switch, but it's the cleanest solution +// StandardStorageTeardown deletes everything in storage so that it's clean for the next test. func StandardStorageTeardown(storage *gtsstorage.Driver) { defer os.RemoveAll(path.Join(os.TempDir(), "gotosocial")) - // Open a storage iterator - iter, err := storage.Iterator(context.Background(), nil) - if err != nil { - panic(err) - } - var keys []string - for iter.Next() { - // Collate all of the storage keys - keys = append(keys, iter.Key()) - } - - // Done with iter - iter.Release() + _ = storage.WalkKeys(context.Background(), func(ctx context.Context, key string) error { + keys = append(keys, key) + return nil + }) for _, key := range keys { - // Ignore errors, we just want to attempt delete all _ = storage.Delete(context.Background(), key) } } -- cgit v1.2.3