From 234128a9233f8121725fa372012c41870bd52b9d Mon Sep 17 00:00:00 2001 From: Lucas Narciso Date: Thu, 11 Oct 2018 09:50:12 -0300 Subject: [PATCH] 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. --- .../lib/explorer/chain/address/token_balance.ex | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/address/token_balance.ex b/apps/explorer/lib/explorer/chain/address/token_balance.ex index c7a9eefed5..3a198e6bf4 100644 --- a/apps/explorer/lib/explorer/chain/address/token_balance.ex +++ b/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.