Skip to content

Commit

Permalink
cleanup badger store
Browse files Browse the repository at this point in the history
  • Loading branch information
okdas committed Aug 15, 2024
1 parent 31bc439 commit 21cfb18
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions kvstore/badger/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,19 @@ func (store *badgerKVStore) GetAll(prefix []byte, descending bool) (keys, values
func (store *badgerKVStore) Exists(key []byte) (bool, error) {
var exists bool
err := store.db.View(func(tx *badgerv4.Txn) error {
_, err := tx.Get(key)
item, err := tx.Get(key)
if err == badgerv4.ErrKeyNotFound {
exists = false
return nil
return ErrBadgerUnableToGetValue
}
if err != nil {
return err
}
exists = true
return nil
// Check if the value is nil
err = item.Value(func(val []byte) error {
exists = len(val) > 0
return nil
})
return err
})
if err != nil {
return false, errors.Join(ErrBadgerUnableToCheckExistence, err)
Expand Down

0 comments on commit 21cfb18

Please sign in to comment.