perf: use store has instead of get in HistoricalInfo (#17400)

This commit is contained in:
fx0x55
2023-08-16 07:26:14 +00:00
committed by GitHub
parent 2d32576c85
commit 53f804df73
+4 -7
View File
@@ -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
}