[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 <grufwub@gmail.com>

* fix missing unwrapped function

Signed-off-by: kim <grufwub@gmail.com>

* add code comment

Signed-off-by: kim <grufwub@gmail.com>

* linter, please take my offering in peace

Signed-off-by: kim <grufwub@gmail.com>

---------

Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2023-03-01 09:44:54 +00:00 committed by GitHub
commit 87c5c42972
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 97 additions and 95 deletions

View file

@ -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 &gtsstorage.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)
}
}