Skip to content

Commit

Permalink
improve indexed_validators search function
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbitfly committed Dec 5, 2022
1 parent e33be7b commit e18f79a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions handlers/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,19 @@ func SearchAhead(w http.ResponseWriter, r *http.Request) {
case "indexed_validators":
// find all validators that have a publickey or index like the search-query
result = &types.SearchAheadValidatorsResult{}

indexNumeric, errParse := strconv.ParseInt(search, 10, 64)
if errParse != nil {
indexNumeric = -1
}
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 CAST(validatorindex AS text) LIKE $1
OR pubkeyhex LIKE LOWER($1)
OR LOWER(validator_names.name) LIKE LOWER($2)
ORDER BY index LIMIT 10`, search+"%", "%"+search+"%")
WHERE validatorindex = $1
OR pubkeyhex LIKE LOWER($2)
OR LOWER(validator_names.name) LIKE LOWER($3)
ORDER BY index LIMIT 10`, indexNumeric, search+"%", "%"+search+"%")
case "indexed_validators_by_eth1_addresses":
if len(search) <= 1 {
break
Expand Down

0 comments on commit e18f79a

Please sign in to comment.