Skip to content

Commit 462f6fb

Browse files
committed
refactor(db): replace if-else chain with switch on record.Type in db.go (gocritic ifElseChain)
1 parent 6e46d15 commit 462f6fb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

db.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ func (db *DB) loadIndexFromWAL() error {
695695

696696
// if we get the end of a batch,
697697
// all records in this batch are ready to be indexed.
698-
if record.Type == LogRecordBatchFinished {
698+
switch record.Type {
699+
case LogRecordBatchFinished:
699700
batchId, err := snowflake.ParseBytes(record.Key)
700701
if err != nil {
701702
return err
@@ -710,12 +711,18 @@ func (db *DB) loadIndexFromWAL() error {
710711
}
711712
// delete indexRecords according to batchId after indexing
712713
delete(indexRecords, uint64(batchId))
713-
} else if record.Type == LogRecordNormal && record.BatchId == mergeFinishedBatchID {
714+
715+
case LogRecordNormal:
714716
// if the record is a normal record and the batch id is 0,
715717
// it means that the record is involved in the merge operation.
716718
// so put the record into index directly.
717-
db.index.Put(record.Key, position)
718-
} else {
719+
if record.BatchId == mergeFinishedBatchID {
720+
db.index.Put(record.Key, position)
721+
break
722+
}
723+
fallthrough
724+
725+
default:
719726
// expired records should not be indexed
720727
if record.IsExpired(now) {
721728
db.index.Delete(record.Key)

0 commit comments

Comments
 (0)