Add order by for token transfers; tune pagination on transaction/token-transfers

pull/5612/head
nikitosing 3 years ago committed by Viktor Baranov
parent d0fa495df0
commit ef4a71972f
  1. 4
      apps/explorer/lib/explorer/chain.ex
  2. 4
      apps/explorer/lib/explorer/chain/token_transfer.ex
  3. 1
      apps/explorer/lib/explorer/chain/transaction.ex

@ -3630,7 +3630,7 @@ defmodule Explorer.Chain do
]
def transaction_to_token_transfers(transaction_hash, options \\ []) when is_list(options) do
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
paging_options = Keyword.get(options, :paging_options, @default_paging_options)
paging_options = options |> Keyword.get(:paging_options, @default_paging_options) |> Map.put(:asc_order, true)
TokenTransfer
|> join(:inner, [token_transfer], transaction in assoc(token_transfer, :transaction))
@ -3641,7 +3641,7 @@ defmodule Explorer.Chain do
)
|> TokenTransfer.page_token_transfer(paging_options)
|> limit(^paging_options.page_size)
|> order_by([token_transfer], asc: token_transfer.inserted_at)
|> order_by([token_transfer], asc: token_transfer.log_index)
|> join_associations(necessity_by_association)
|> Repo.all()
end

@ -215,6 +215,10 @@ defmodule Explorer.Chain.TokenTransfer do
def page_token_transfer(query, %PagingOptions{key: nil}), do: query
def page_token_transfer(query, %PagingOptions{key: {token_id}, asc_order: true}) do
where(query, [tt], tt.token_id > ^token_id)
end
def page_token_transfer(query, %PagingOptions{key: {token_id}}) do
where(query, [tt], tt.token_id < ^token_id)
end

@ -431,6 +431,7 @@ defmodule Explorer.Chain.Transaction do
where:
tt.token_contract_address_hash == ^address_hash or tt.to_address_hash == ^address_hash or
tt.from_address_hash == ^address_hash,
order_by: [asc: tt.log_index],
preload: [:token, [from_address: :names], [to_address: :names]]
)

Loading…
Cancel
Save