Avoid redundant calculation of @burn_address_hash

Use the available @burn_address_hash module attribute instead of
calculating this value again in token_holders_query/1.
pull/904/head
Lucas Narciso 6 years ago
parent c23c10520d
commit 234128a923
No known key found for this signature in database
GPG Key ID: 9E89F4CF3FBAB001
  1. 10
      apps/explorer/lib/explorer/chain/address/token_balance.ex

@ -64,6 +64,9 @@ defmodule Explorer.Chain.Address.TokenBalance do
|> unique_constraint(:block_number, name: :token_balances_address_hash_block_number_index)
end
{:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000")
@burn_address_hash burn_address_hash
@doc """
Builds an `Ecto.Query` to fetch the last token balances that have value greater than 0.
@ -110,12 +113,10 @@ defmodule Explorer.Chain.Address.TokenBalance do
end
defp token_holders_query(contract_address_hash) do
{:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000")
from(
tb in TokenBalance,
distinct: :address_hash,
where: tb.token_contract_address_hash == ^contract_address_hash and tb.address_hash != ^burn_address_hash,
where: tb.token_contract_address_hash == ^contract_address_hash and tb.address_hash != ^@burn_address_hash,
order_by: [desc: :block_number]
)
end
@ -130,9 +131,6 @@ defmodule Explorer.Chain.Address.TokenBalance do
)
end
{:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000")
@burn_address_hash burn_address_hash
@doc """
Builds an `Ecto.Query` to fetch the unfetched token balances.

Loading…
Cancel
Save