Skip to content

Commit

Permalink
Merge pull request #37 from ipfs/feat/fast-has
Browse files Browse the repository at this point in the history
make has faster
  • Loading branch information
Stebalien authored Oct 4, 2018
2 parents aa6f265 + ef7c695 commit 0c326d3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ func (t *txn) Get(key ds.Key) ([]byte, error) {
}

func (t *txn) Has(key ds.Key) (bool, error) {
_, err := t.Get(key)

if err == nil {
return true, nil
} else if err == ds.ErrNotFound {
_, err := t.txn.Get(key.Bytes())
switch err {
case badger.ErrKeyNotFound:
return false, nil
case nil:
return true, nil
default:
return false, err
}

return false, err
}

func (t *txn) Delete(key ds.Key) error {
Expand Down

0 comments on commit 0c326d3

Please sign in to comment.