Skip to content

Commit 6d72d76

Browse files
committed
feat: use the built-in max/min to simplify the code
Signed-off-by: pingshuijie <pingshuijie@outlook.com>
1 parent 0b04430 commit 6d72d76

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

db/migrations/20220109122505_logs.up.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ func LogsUp(ctx context.Context, tx *bun.Tx) error {
165165

166166
for i := start; i <= end; i += batchSize {
167167
bs := i
168-
be := i + batchSize - 1
169-
if be > end {
170-
be = end
171-
}
168+
be := min(i+batchSize-1, end)
172169

173170
logger.Debug("migrating batch", "batch_start", bs, "batch_end", be)
174171
// Fetch all logs for the batch rounds.

rpc/eth/api.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ func (api *publicAPI) roundParamFromBlockNum(ctx context.Context, logger *loggin
182182
logger.Error("failed to get last retained block from indexer", "err", err)
183183
return 0, ErrInternalError
184184
}
185-
if clrBlk.Header.Round < ilrRound {
186-
earliest = ilrRound
187-
} else {
188-
earliest = clrBlk.Header.Round
189-
}
185+
earliest = max(clrBlk.Header.Round, ilrRound)
190186
return earliest, nil
191187
default:
192188
if int64(blockNum) < 0 {

0 commit comments

Comments
 (0)