From 46bea8742ba941e63eb36a96072c2cfeba7f782b Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Sat, 24 Feb 2024 14:03:09 +0100 Subject: [PATCH] more debug logging --- database/database.go | 6 +++--- services/website/webserver.go | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/database/database.go b/database/database.go index 61c4746..f9dbd2c 100644 --- a/database/database.go +++ b/database/database.go @@ -116,14 +116,14 @@ func (s *DatabaseService) GetDataAPILatestBid(relay string) (*DataAPIBuilderBidE } func (s *DatabaseService) GetTopRelays(since, until time.Time) (res []*TopRelayEntry, err error) { - query := `SELECT relay, count(relay) as payloads FROM mainnet_data_api_payload_delivered 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 inserted_at > $1 AND inserted_at < $2 GROUP BY relay ORDER BY payloads DESC;` err = s.DB.Select(&res, query, since.UTC(), until.UTC()) return res, err } func (s *DatabaseService) GetTopBuilders(since, until time.Time, relay string) (res []*TopBuilderEntry, err error) { query := `SELECT extra_data, count(extra_data) as blocks FROM ( - SELECT distinct(slot), extra_data FROM mainnet_data_api_payload_delivered WHERE inserted_at > $1 AND inserted_at < $2` + SELECT distinct(slot), extra_data FROM ` + TableDataAPIPayloadDelivered + ` WHERE inserted_at > $1 AND inserted_at < $2` if relay != "" { query += ` AND relay = '` + relay + `'` } @@ -144,7 +144,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 mainnet_data_api_payload_delivered WHERE inserted_at > $1 AND inserted_at < $2 + SELECT distinct(slot), extra_data, coinbase_diff_eth FROM ` + TableDataAPIPayloadDelivered + ` WHERE inserted_at > $1 AND inserted_at < $2 ) AS x GROUP BY extra_data ORDER BY total_profit DESC;` diff --git a/services/website/webserver.go b/services/website/webserver.go index bf7a5c1..5b02274 100644 --- a/services/website/webserver.go +++ b/services/website/webserver.go @@ -152,26 +152,29 @@ func (srv *Webserver) getStatsForHours(duration time.Duration) (stats *Stats, er now := time.Now().UTC() since := now.Add(-1 * duration.Abs()) + srv.log.Debug("- loading top relays...") startTime := time.Now() topRelays, err := srv.db.GetTopRelays(since, now) if err != nil { return nil, err } - srv.log.WithField("duration", time.Since(startTime).String()).Debug("got top relays") + srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got top relays") + srv.log.Debug("- loading top builders...") startTime = time.Now() topBuilders, err := srv.db.GetTopBuilders(since, now, "") if err != nil { return nil, err } - srv.log.WithField("duration", time.Since(startTime).String()).Debug("got top builders") + srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got top builders") + srv.log.Debug("- loading builder profits...") startTime = time.Now() builderProfits, err := srv.db.GetBuilderProfits(since, now) if err != nil { return nil, err } - srv.log.WithField("duration", time.Since(startTime).String()).Debug("got builder profits") + srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got builder profits") stats = &Stats{ Since: since, @@ -184,6 +187,7 @@ func (srv *Webserver) getStatsForHours(duration time.Duration) (stats *Stats, er } // Query builders for each relay + srv.log.Debug("- loading builders per relay...") startTime = time.Now() for _, relay := range topRelays { topBuildersForRelay, err := srv.db.GetTopBuilders(since, now, relay.Relay) @@ -192,7 +196,7 @@ func (srv *Webserver) getStatsForHours(duration time.Duration) (stats *Stats, er } stats.TopBuildersByRelay[relay.Relay] = consolidateBuilderEntries(topBuildersForRelay) } - srv.log.WithField("duration", time.Since(startTime).String()).Debug("got builders per relay") + srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got builders per relay") return stats, nil }