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 \\ []
)
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}
query =
from(transaction in Transaction,
inner_join: log in assoc(transaction, :logs),
order_by: [desc: transaction.block_number, desc: transaction.index],
preload: [:logs],
from(log in Log,
inner_join: transaction in assoc(log, :transaction),
order_by: [desc: transaction.block_number, desc: transaction.index, asc: log.index],
where:
(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
@ -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 and
log.index > ^log_index)),
limit: ^paging_options.page_size,
distinct: transaction.hash
limit: ^paging_options.page_size
)
query
|> Repo.all()
|> Enum.flat_map(fn transaction -> transaction.logs end)
|> Enum.take(paging_options.page_size)
end

Loading…
Cancel
Save