diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index 2aa291cb6f..4723be2fcb 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -238,12 +238,8 @@ defmodule Explorer.Chain.TokenTransfer do def address_to_unique_tokens(contract_address_hash) do from( tt in TokenTransfer, - join: t in Token, - on: tt.token_contract_address_hash == t.contract_address_hash, - join: ts in Transaction, - on: tt.transaction_hash == ts.hash, - where: t.contract_address_hash == ^contract_address_hash and t.type == "ERC-721", - order_by: [desc: ts.block_number], + where: tt.token_contract_address_hash == ^contract_address_hash, + order_by: [desc: tt.block_number], distinct: tt.token_id, preload: [:to_address], select: tt diff --git a/apps/explorer/priv/repo/migrations/20190827120224_add_index_on_token_transfer_token_id.exs b/apps/explorer/priv/repo/migrations/20190827120224_add_index_on_token_transfer_token_id.exs new file mode 100644 index 0000000000..b92f216fd4 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20190827120224_add_index_on_token_transfer_token_id.exs @@ -0,0 +1,7 @@ +defmodule Explorer.Repo.Migrations.AddIndexOnTokenTransferTokenId do + use Ecto.Migration + + def change do + create_if_not_exists(index(:token_transfers, [:token_id])) + end +end