From 26163983c5b186bc1c64d97e3e32c4c79a0055ea Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:29:16 +0000 Subject: [PATCH 1/4] fix(search): improve performance of search validator by name queries --- handlers/search.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/handlers/search.go b/handlers/search.go index 9a26833ec3..f409952eba 100644 --- a/handlers/search.go +++ b/handlers/search.go @@ -176,10 +176,8 @@ func SearchAhead(w http.ResponseWriter, r *http.Request) { } else { err = db.ReaderDb.Select(result, ` SELECT validatorindex AS index, pubkeyhex AS pubkey - FROM validators - LEFT JOIN validator_names ON validators.pubkey = validator_names.publickey - WHERE LOWER(validator_names.name) LIKE LOWER($1) - ORDER BY index LIMIT 10`, search+"%") + FROM validators WHERE pubkey IN + (SELECT publickey FROM validator_names WHERE LOWER(validator_names.name) LIKE LOWER($1) LIMIT 10)`, search+"%") } case "eth1_addresses": if utils.IsValidEnsDomain(search) { @@ -216,12 +214,9 @@ func SearchAhead(w http.ResponseWriter, r *http.Request) { } else if thresholdHexLikeRE.MatchString(lowerStrippedSearch) { err = db.ReaderDb.Select(result, `SELECT validatorindex AS index, pubkeyhex as pubkey FROM validators WHERE pubkeyhex LIKE ($1 || '%')`, lowerStrippedSearch) } else { - err = db.ReaderDb.Select(result, ` - SELECT validatorindex AS index, pubkeyhex AS pubkey - FROM validators - LEFT JOIN validator_names ON validators.pubkey = validator_names.publickey - WHERE LOWER(validator_names.name) LIKE LOWER($1) - ORDER BY index LIMIT 10`, search+"%") + err = db.ReaderDb.Select(result, `SELECT validatorindex AS index, pubkeyhex AS pubkey + FROM validators WHERE pubkey IN + (SELECT publickey FROM validator_names WHERE LOWER(validator_names.name) LIKE LOWER($1) LIMIT 10)`, search+"%") } case "validators_by_pubkey": if !thresholdHexLikeRE.MatchString(lowerStrippedSearch) { @@ -428,4 +423,4 @@ func FindValidatorIndicesByEth1Address(search string) (types.SearchValidatorsByE return nil, fmt.Errorf("error reading result data: %v", err) } return *result, nil -} +} From c22233e055286a8a62b40c989a51afe341e1cf03 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:32:02 +0000 Subject: [PATCH 2/4] chore(search): gofmt file --- handlers/search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/search.go b/handlers/search.go index f409952eba..94847e4809 100644 --- a/handlers/search.go +++ b/handlers/search.go @@ -423,4 +423,4 @@ func FindValidatorIndicesByEth1Address(search string) (types.SearchValidatorsByE return nil, fmt.Errorf("error reading result data: %v", err) } return *result, nil -} +} From f09f1cec90cdca45ec4cde1836bdf1e2e6c28170 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:45:05 +0000 Subject: [PATCH 3/4] fix(monitoring): throttle service status updates --- services/status.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/status.go b/services/status.go index 915557086e..7088d6a187 100644 --- a/services/status.go +++ b/services/status.go @@ -3,6 +3,7 @@ package services import ( "encoding/json" "os" + "time" "github.com/gobitfly/eth2-beaconchain-explorer/db" "github.com/gobitfly/eth2-beaconchain-explorer/utils" @@ -10,10 +11,19 @@ import ( ) // Report the status of a particular service, will add current Pid and executable name +// Throttle calls to 1/min for each service name so that we don't report too often +var lastStatusUpdate = make(map[string]time.Time) + func ReportStatus(name, status string, metadata *json.RawMessage) { if !utils.Config.ReportServiceStatus { return } + + if lastUpdate, ok := lastStatusUpdate[name]; ok { + if time.Since(lastUpdate) < time.Minute { + return + } + } pid := os.Getpid() execName, err := os.Executable() if err != nil { @@ -33,4 +43,5 @@ func ReportStatus(name, status string, metadata *json.RawMessage) { if err != nil { utils.LogError(err, "error reporting service status", 0, map[string]interface{}{"name": name, "status": status}) } + lastStatusUpdate[name] = time.Now() } From a4d958c85a50de4e541d1ad1bb54c27c73ea5cbd Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer Date: Mon, 30 Sep 2024 09:31:33 +0200 Subject: [PATCH 4/4] chore(monitoring): move comment to ReportStatus func --- services/status.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/status.go b/services/status.go index 7088d6a187..88975fe1bb 100644 --- a/services/status.go +++ b/services/status.go @@ -10,10 +10,10 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/version" ) -// Report the status of a particular service, will add current Pid and executable name -// Throttle calls to 1/min for each service name so that we don't report too often var lastStatusUpdate = make(map[string]time.Time) +// Report the status of a particular service, will add current Pid and executable name +// Throttle calls to 1/min for each service name so that we don't report too often func ReportStatus(name, status string, metadata *json.RawMessage) { if !utils.Config.ReportServiceStatus { return