fix pagination

pull/1956/head
Ayrat Badykov 6 years ago
parent 45ad353e22
commit 0dc13697a6
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 13
      apps/explorer/lib/explorer/chain.ex

@ -287,15 +287,14 @@ defmodule Explorer.Chain do
options \\ [] options \\ []
) )
when is_list(options) do when is_list(options) do
paging_options = Keyword.get(options, :paging_options) paging_options = Keyword.get(options, :paging_options) || %PagingOptions{page_size: 50}
{block_number, transaction_index, log_index} = paging_options.key || {BlockNumberCache.max_number(), 0, 0} {block_number, transaction_index, log_index} = paging_options.key || {BlockNumberCache.max_number(), 0, 0}
query = query =
from(transaction in Transaction, from(log in Log,
inner_join: log in assoc(transaction, :logs), inner_join: transaction in assoc(log, :transaction),
order_by: [desc: transaction.block_number, desc: transaction.index], order_by: [desc: transaction.block_number, desc: transaction.index, asc: log.index],
preload: [:logs],
where: where:
(transaction.from_address_hash == ^address_hash or transaction.to_address_hash == ^address_hash or (transaction.from_address_hash == ^address_hash or transaction.to_address_hash == ^address_hash or
transaction.created_contract_address_hash == ^address_hash) and log.address_hash == ^address_hash and transaction.created_contract_address_hash == ^address_hash) and log.address_hash == ^address_hash and
@ -303,13 +302,11 @@ defmodule Explorer.Chain do
(transaction.block_number == ^block_number and transaction.index > ^transaction_index) or (transaction.block_number == ^block_number and transaction.index > ^transaction_index) or
(transaction.block_number == ^block_number and transaction.index == ^transaction_index and (transaction.block_number == ^block_number and transaction.index == ^transaction_index and
log.index > ^log_index)), log.index > ^log_index)),
limit: ^paging_options.page_size, limit: ^paging_options.page_size
distinct: transaction.hash
) )
query query
|> Repo.all() |> Repo.all()
|> Enum.flat_map(fn transaction -> transaction.logs end)
|> Enum.take(paging_options.page_size) |> Enum.take(paging_options.page_size)
end end

Loading…
Cancel
Save