Skip to content

Commit 7e17f88

Browse files
committed
misc(clickhouse): use final instead of manually handling duplicate rows when fetching balances from clickhouse
1 parent d5c55c9 commit 7e17f88

1 file changed

Lines changed: 1 addition & 9 deletions

File tree

db/bigtable.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -808,25 +808,17 @@ func (bigtable *Bigtable) getValidatorBalanceHistoryClickhouse(validators []uint
808808
epoch_timestamp,
809809
balance,
810810
effective_balance
811-
FROM legacy_validator_epoch_balances WHERE epoch_timestamp >= ? AND epoch_timestamp <= ? AND validator_index IN (?) ORDER BY epoch_timestamp ASC`
811+
FROM legacy_validator_epoch_balances FINAL WHERE epoch_timestamp >= ? AND epoch_timestamp <= ? AND validator_index IN (?) ORDER BY epoch_timestamp ASC`
812812

813813
err := ClickhouseReaderDb.Select(&rows, query, startEpochTs, endEpochTs, validators)
814814
if err != nil {
815815
logger.Error(err)
816816
return nil, err
817817
}
818818

819-
// the query might return duplicate rows, so we need to deduplicate them
820-
// the key is the validator index and the epoch, so we can use that to deduplicate
821-
seen := make(map[string]bool)
822819
res := make(map[uint64][]*types.ValidatorBalance, len(validators))
823820
for _, r := range rows {
824821
epoch := uint64(utils.TimeToEpoch(r.EpochTimestamp))
825-
seenKey := fmt.Sprintf("%d:%d", r.ValidatorIndex, epoch)
826-
if seen[seenKey] {
827-
continue
828-
}
829-
seen[seenKey] = true
830822
if res[r.ValidatorIndex] == nil {
831823
res[r.ValidatorIndex] = make([]*types.ValidatorBalance, 0)
832824
}

0 commit comments

Comments
 (0)