mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
cache or not
Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
parent
f15bc8d345
commit
10aeeed669
1 changed files with 15 additions and 21 deletions
|
|
@ -78,33 +78,27 @@ type indexReader struct {
|
||||||
timings *readTimings
|
timings *readTimings
|
||||||
}
|
}
|
||||||
|
|
||||||
func readHistoryIndexWithCache(db ethdb.KeyValueReader, state stateIdent) []byte {
|
// loadIndexData loads the index data associated with the specified state.
|
||||||
|
func loadIndexData(db ethdb.KeyValueReader, state stateIdent, timings *readTimings, cacheRead bool) ([]*indexBlockDesc, error) {
|
||||||
|
start := time.Now()
|
||||||
key := state.String()
|
key := state.String()
|
||||||
if val, ok := historyIndexCache.Get(key); ok {
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
var blob []byte
|
var blob []byte
|
||||||
|
if cacheRead && historyIndexCache.Contains(key) {
|
||||||
|
blob, _ = historyIndexCache.Get(key)
|
||||||
|
} else {
|
||||||
if state.account {
|
if state.account {
|
||||||
blob = rawdb.ReadAccountHistoryIndex(db, state.addressHash)
|
blob = rawdb.ReadAccountHistoryIndex(db, state.addressHash)
|
||||||
} else {
|
} else {
|
||||||
blob = rawdb.ReadStorageHistoryIndex(db, state.addressHash, state.storageHash)
|
blob = rawdb.ReadStorageHistoryIndex(db, state.addressHash, state.storageHash)
|
||||||
}
|
}
|
||||||
if len(blob) > 0 {
|
|
||||||
historyIndexCache.Add(key, blob)
|
|
||||||
}
|
}
|
||||||
return blob
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadIndexData loads the index data associated with the specified state.
|
|
||||||
func loadIndexData(db ethdb.KeyValueReader, state stateIdent, timings *readTimings) ([]*indexBlockDesc, error) {
|
|
||||||
start := time.Now()
|
|
||||||
blob := readHistoryIndexWithCache(db, state)
|
|
||||||
if timings != nil {
|
if timings != nil {
|
||||||
timings.kvdbIndex = time.Since(start)
|
timings.kvdbIndex = time.Since(start)
|
||||||
}
|
}
|
||||||
if len(blob) == 0 {
|
if len(blob) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
historyIndexCache.Add(key, blob)
|
||||||
return parseIndex(blob)
|
return parseIndex(blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +110,7 @@ func newIndexReader(db ethdb.KeyValueReader, state stateIdent) (*indexReader, er
|
||||||
|
|
||||||
// Helper to allow passing timings
|
// Helper to allow passing timings
|
||||||
func newIndexReaderWithTimings(db ethdb.KeyValueReader, state stateIdent, timings *readTimings) (*indexReader, error) {
|
func newIndexReaderWithTimings(db ethdb.KeyValueReader, state stateIdent, timings *readTimings) (*indexReader, error) {
|
||||||
descList, err := loadIndexData(db, state, timings)
|
descList, err := loadIndexData(db, state, timings, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +134,7 @@ func (r *indexReader) refresh() error {
|
||||||
delete(r.readers, last.id)
|
delete(r.readers, last.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
descList, err := loadIndexData(r.db, r.state, r.timings)
|
descList, err := loadIndexData(r.db, r.state, r.timings, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue