Skip to content

Commit 76d998d

Browse files
authored
fix(shwap/store): avoid double cache check (#3788)
* `Store` checks the combined cache already, so there is no need to recheck it in `CachedStore` * `Store.HasByHeight` to use `cache.Has` to check accessor presence instead of `cache.Get` This fixes a performance bug, rather than something that was broken.
1 parent b6be349 commit 76d998d

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

store/store.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,7 @@ func (s *Store) HasByHeight(ctx context.Context, height uint64) (bool, error) {
356356
}
357357

358358
func (s *Store) hasByHeight(height uint64) (bool, error) {
359-
acc, err := s.cache.Get(height)
360-
if err == nil {
361-
utils.CloseAndLog(log, "accessor", acc)
359+
if s.cache.Has(height) {
362360
return true, nil
363361
}
364362

store/store_cache.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ func (s *Store) WithCache(name string, size int) (*CachedStore, error) {
4343

4444
// HasByHeight checks if accessor for the height is present.
4545
func (cs *CachedStore) HasByHeight(ctx context.Context, height uint64) (bool, error) {
46-
if cs.combinedCache.Has(height) {
47-
return true, nil
48-
}
49-
46+
// store checks the combinedCache itself, so we can simply passthrough the call
5047
return cs.store.HasByHeight(ctx, height)
5148
}
5249

0 commit comments

Comments
 (0)