Use the goleveldb Has() API.
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.
This commit is contained in:
parent
624bbb3216
commit
0247ddff18
2 changed files with 6 additions and 16 deletions
|
@ -202,14 +202,9 @@ func (db *LevelDb) ExistsSha(sha *btcwire.ShaHash) (bool, error) {
|
||||||
// returns true if it is present in the database.
|
// returns true if it is present in the database.
|
||||||
// CALLED WITH LOCK HELD
|
// CALLED WITH LOCK HELD
|
||||||
func (db *LevelDb) blkExistsSha(sha *btcwire.ShaHash) (bool, error) {
|
func (db *LevelDb) blkExistsSha(sha *btcwire.ShaHash) (bool, error) {
|
||||||
_, err := db.getBlkLoc(sha)
|
key := shaBlkToKey(sha)
|
||||||
switch err {
|
|
||||||
case nil:
|
return db.lDb.Has(key, db.ro)
|
||||||
return true, nil
|
|
||||||
case leveldb.ErrNotFound, database.ErrBlockShaMissing:
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchBlockShaByHeight returns a block hash based on its height in the
|
// FetchBlockShaByHeight returns a block hash based on its height in the
|
||||||
|
|
|
@ -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
|
// existsTxSha returns if the given tx sha exists in the database.o
|
||||||
// Must be called with the db lock held.
|
// Must be called with the db lock held.
|
||||||
func (db *LevelDb) existsTxSha(txSha *btcwire.ShaHash) (bool, error) {
|
func (db *LevelDb) existsTxSha(txSha *btcwire.ShaHash) (bool, error) {
|
||||||
_, _, _, _, err := db.getTxData(txSha)
|
key := shaTxToKey(txSha)
|
||||||
switch err {
|
|
||||||
case nil:
|
return db.lDb.Has(key, db.ro)
|
||||||
return true, nil
|
|
||||||
case leveldb.ErrNotFound:
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchTxByShaList returns the most recent tx of the name fully spent or not
|
// FetchTxByShaList returns the most recent tx of the name fully spent or not
|
||||||
|
|
Loading…
Reference in a new issue