diff --git a/database/database.go b/database/database.go index cf351a2..fd968b5 100644 --- a/database/database.go +++ b/database/database.go @@ -133,7 +133,7 @@ func (s *DatabaseService) GetTopRelays(since, until time.Time) (res []*TopRelayE endSlot := timeToSlot(until) // query := `SELECT relay, count(relay) as payloads FROM ` + TableDataAPIPayloadDelivered + ` WHERE inserted_at > $1 AND inserted_at < $2 GROUP BY relay ORDER BY payloads DESC;` - query := `SELECT relay, count(relay) as payloads FROM ` + TableDataAPIPayloadDelivered + ` WHERE slot >= $1 AND slot <= $2 GROUP BY relay ORDER BY payloads DESC;` + query := `SELECT relay, count(relay) as payloads FROM ` + TableDataAPIPayloadDelivered + ` WHERE value_check_ok IS NOT NULL AND slot >= $1 AND slot <= $2 GROUP BY relay ORDER BY payloads DESC;` err = s.DB.Select(&res, query, startSlot, endSlot) return res, err } @@ -143,7 +143,7 @@ func (s *DatabaseService) GetTopBuilders(since, until time.Time, relay string) ( endSlot := timeToSlot(until) query := `SELECT extra_data, count(extra_data) as blocks FROM ( - SELECT distinct(slot), extra_data FROM ` + TableDataAPIPayloadDelivered + ` WHERE slot >= $1 AND slot <= $2` + SELECT distinct(slot), extra_data FROM ` + TableDataAPIPayloadDelivered + ` WHERE value_check_ok IS NOT NULL AND slot >= $1 AND slot <= $2` if relay != "" { query += ` AND relay = '` + relay + `'` } @@ -167,7 +167,7 @@ func (s *DatabaseService) GetBuilderProfits(since, until time.Time) (res []*Buil round(sum(CASE WHEN coinbase_diff_eth IS NOT NULL THEN coinbase_diff_eth ELSE 0 END), 4) as total_profit, round(abs(sum(CASE WHEN coinbase_diff_eth < 0 THEN coinbase_diff_eth ELSE 0 END)), 4) as total_subsidies FROM ( - SELECT distinct(slot), extra_data, coinbase_diff_eth FROM ` + TableDataAPIPayloadDelivered + ` WHERE slot >= $1 AND slot <= $2 + SELECT distinct(slot), extra_data, coinbase_diff_eth FROM ` + TableDataAPIPayloadDelivered + ` WHERE value_check_ok IS NOT NULL AND slot >= $1 AND slot <= $2 ) AS x GROUP BY extra_data ORDER BY total_profit DESC;`