Remove joins from token transfers' query

Once we have the block_number denormalized in the token transfer's
table, the query doesn't need to join with transaction and block
anymore.
pull/1124/head
Felipe Renan 6 years ago
parent 2ad1042de2
commit e880788232
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex
  2. 8
      apps/explorer/lib/explorer/chain/token_transfer.ex

@ -43,7 +43,7 @@
<%= link( <%= link(
gettext( gettext(
"Block #%{number}", "Block #%{number}",
number: @transfer.transaction.block_number number: @transfer.block_number
), ),
class: "mr-2 mr-sm-0 text-muted", class: "mr-2 mr-sm-0 text-muted",
to: block_path(BlockScoutWeb.Endpoint, :show, @transfer.transaction.block_number) to: block_path(BlockScoutWeb.Endpoint, :show, @transfer.transaction.block_number)

@ -26,7 +26,7 @@ defmodule Explorer.Chain.TokenTransfer do
import Ecto.{Changeset, Query} import Ecto.{Changeset, Query}
alias Explorer.Chain.{Address, Block, Hash, Token, TokenTransfer, Transaction} alias Explorer.Chain.{Address, Hash, Token, TokenTransfer, Transaction}
alias Explorer.{PagingOptions, Repo} alias Explorer.{PagingOptions, Repo}
@default_paging_options %PagingOptions{page_size: 50} @default_paging_options %PagingOptions{page_size: 50}
@ -121,13 +121,9 @@ defmodule Explorer.Chain.TokenTransfer do
query = query =
from( from(
tt in TokenTransfer, tt in TokenTransfer,
join: t in Transaction,
on: tt.transaction_hash == t.hash,
join: b in Block,
on: t.block_hash == b.hash,
where: tt.token_contract_address_hash == ^token_address_hash, where: tt.token_contract_address_hash == ^token_address_hash,
preload: [{:transaction, :block}, :token, :from_address, :to_address], preload: [{:transaction, :block}, :token, :from_address, :to_address],
order_by: [desc: b.timestamp] order_by: [desc: tt.block_number]
) )
query query

Loading…
Cancel
Save