perf: use store has instead of get in HistoricalInfo (#17400)
This commit is contained in:
parent
2d32576c85
commit
53f804df73
@ -2,9 +2,6 @@ package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
@ -28,13 +25,13 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error {
|
||||
// over the historical entries starting from the most recent version to be pruned
|
||||
// and then return at the first empty entry.
|
||||
for i := sdkCtx.BlockHeight() - int64(entryNum); i >= 0; i-- {
|
||||
_, err := k.HistoricalInfo.Get(ctx, uint64(i))
|
||||
has, err := k.HistoricalInfo.Has(ctx, uint64(i))
|
||||
if err != nil {
|
||||
if errors.Is(err, collections.ErrNotFound) {
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
if !has {
|
||||
break
|
||||
}
|
||||
if err = k.HistoricalInfo.Remove(ctx, uint64(i)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user