Skip to content

Commit

Permalink
Use the goleveldb Has() API.
Browse files Browse the repository at this point in the history
This change converts the leveldb database's ExistsSha() and
ExistsTxSha to use the goleveldb API.  Has() only returns if
the key exists and does not need to read the entire value into
memory resulting in less disk i/o and much less GC.
  • Loading branch information
dajohi committed Jan 31, 2015
1 parent 624bbb3 commit 0247ddf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 3 additions & 8 deletions database/ldb/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,9 @@ func (db *LevelDb) ExistsSha(sha *btcwire.ShaHash) (bool, error) {
// returns true if it is present in the database.
// CALLED WITH LOCK HELD
func (db *LevelDb) blkExistsSha(sha *btcwire.ShaHash) (bool, error) {
_, err := db.getBlkLoc(sha)
switch err {
case nil:
return true, nil
case leveldb.ErrNotFound, database.ErrBlockShaMissing:
return false, nil
}
return false, err
key := shaBlkToKey(sha)

return db.lDb.Has(key, db.ro)
}

// FetchBlockShaByHeight returns a block hash based on its height in the
Expand Down
11 changes: 3 additions & 8 deletions database/ldb/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,9 @@ func (db *LevelDb) ExistsTxSha(txsha *btcwire.ShaHash) (bool, error) {
// existsTxSha returns if the given tx sha exists in the database.o
// Must be called with the db lock held.
func (db *LevelDb) existsTxSha(txSha *btcwire.ShaHash) (bool, error) {
_, _, _, _, err := db.getTxData(txSha)
switch err {
case nil:
return true, nil
case leveldb.ErrNotFound:
return false, nil
}
return false, err
key := shaTxToKey(txSha)

return db.lDb.Has(key, db.ro)
}

// FetchTxByShaList returns the most recent tx of the name fully spent or not
Expand Down

0 comments on commit 0247ddf

Please sign in to comment.