From 0dc13697a67ab5114e4dfe2144335115fb7e6cbd Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 16 May 2019 12:19:31 +0300 Subject: [PATCH] fix pagination --- apps/explorer/lib/explorer/chain.ex | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 22d0a0cd6a..4fa6460f16 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/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