Add minor optimization to transaction store fetch.

This commit adds a quick check to the transaction store fetch code which
simply returns an empty store if no hashes were requested rather than
bothering the db with an empty list.
This commit is contained in:
Dave Collins 2013-10-11 10:22:23 -05:00
parent e888372019
commit 39e7e5c4a1

View file

@ -102,11 +102,16 @@ func disconnectTransactions(txStore TxStore, block *btcutil.Block) error {
// fetchTxStoreMain fetches transaction data about the provided set of // fetchTxStoreMain fetches transaction data about the provided set of
// transactions from the point of view of the end of the main chain. // transactions from the point of view of the end of the main chain.
func fetchTxStoreMain(db btcdb.Db, txSet map[btcwire.ShaHash]bool) TxStore { func fetchTxStoreMain(db btcdb.Db, txSet map[btcwire.ShaHash]bool) TxStore {
// Just return an empty store now if there are no requested hashes.
txStore := make(TxStore)
if len(txSet) == 0 {
return txStore
}
// The transaction store map needs to have an entry for every requested // The transaction store map needs to have an entry for every requested
// transaction. By default, all the transactions are marked as missing. // transaction. By default, all the transactions are marked as missing.
// Each entry will be filled in with the appropriate data below. // Each entry will be filled in with the appropriate data below.
txList := make([]*btcwire.ShaHash, 0, len(txSet)) txList := make([]*btcwire.ShaHash, 0, len(txSet))
txStore := make(TxStore)
for hash := range txSet { for hash := range txSet {
hashCopy := hash hashCopy := hash
txStore[hash] = &TxData{Hash: &hashCopy, Err: btcdb.TxShaMissing} txStore[hash] = &TxData{Hash: &hashCopy, Err: btcdb.TxShaMissing}