Skip to content

Commit

Permalink
fix(shwap/store): avoid double cache check (celestiaorg#3788)
Browse files Browse the repository at this point in the history
* `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.
  • Loading branch information
Wondertan authored Oct 6, 2024
1 parent b6be349 commit 76d998d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
4 changes: 1 addition & 3 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ func (s *Store) HasByHeight(ctx context.Context, height uint64) (bool, error) {
}

func (s *Store) hasByHeight(height uint64) (bool, error) {
acc, err := s.cache.Get(height)
if err == nil {
utils.CloseAndLog(log, "accessor", acc)
if s.cache.Has(height) {
return true, nil
}

Expand Down
5 changes: 1 addition & 4 deletions store/store_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func (s *Store) WithCache(name string, size int) (*CachedStore, error) {

// HasByHeight checks if accessor for the height is present.
func (cs *CachedStore) HasByHeight(ctx context.Context, height uint64) (bool, error) {
if cs.combinedCache.Has(height) {
return true, nil
}

// store checks the combinedCache itself, so we can simply passthrough the call
return cs.store.HasByHeight(ctx, height)
}

Expand Down

0 comments on commit 76d998d

Please sign in to comment.