Skip to content

Commit

Permalink
(BIDS-2369) optimize GetTotalAmountWithdrawn
Browse files Browse the repository at this point in the history
  • Loading branch information
LuccaBitfly committed Oct 2, 2023
1 parent d9910fb commit 2711c31
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2379,12 +2379,16 @@ func GetTotalAmountWithdrawn() (sum uint64, count uint64, err error) {
Sum uint64 `db:"sum"`
Count uint64 `db:"count"`
}{}
lastExportedDay, err := GetLastExportedStatisticDay()
if err != nil {
return 0, 0, fmt.Errorf("error getting latest exported statistic day for withdrawals count: %w", err)
}
err = ReaderDb.Get(&res, `
SELECT
COALESCE(sum(w.amount), 0) as sum,
COALESCE(count(*), 0) as count
FROM blocks_withdrawals w
INNER JOIN blocks b ON b.blockroot = w.block_root AND b.status = '1'`)
COALESCE(SUM(withdrawals_amount_total), 0) as sum,
COALESCE(SUM(withdrawals_total), 0) as count
FROM validator_stats
WHERE day = $1`, lastExportedDay)
return res.Sum, res.Count, err
}

Expand Down

0 comments on commit 2711c31

Please sign in to comment.