sort records for pagination

pull/2366/head
Ayrat Badykov 5 years ago
parent 3ede158963
commit 9a95541797
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 19
      apps/explorer/lib/explorer/etherscan/logs.ex

@ -5,7 +5,7 @@ defmodule Explorer.Etherscan.Logs do
""" """
import Ecto.Query, only: [from: 2, where: 3, subquery: 1] import Ecto.Query, only: [from: 2, where: 3, subquery: 1, order_by: 3]
alias Explorer.Chain.{Block, InternalTransaction, Log, Transaction} alias Explorer.Chain.{Block, InternalTransaction, Log, Transaction}
alias Explorer.Repo alias Explorer.Repo
@ -38,7 +38,7 @@ defmodule Explorer.Etherscan.Logs do
:type :type
] ]
@default_paging_options %{block_number: nil, transaction_index: nil} @default_paging_options %{block_number: nil, transaction_index: nil, log_index: nil}
@doc """ @doc """
Gets a list of logs that meet the criteria in a given filter map. Gets a list of logs that meet the criteria in a given filter map.
@ -240,5 +240,18 @@ defmodule Explorer.Etherscan.Logs do
defp where_multiple_topics_match(query, _, _, _), do: query defp where_multiple_topics_match(query, _, _, _), do: query
defp page_logs(query, _paging_options), do: query defp page_logs(query, %{block_number: nil, transaction_index: nil, log_index: nil}) do
query
|> order_by([log], asc: log.index)
end
defp page_logs(query, %{block_number: block_number, transaction_index: transaction_index, log_index: log_index}) do
sorted_query = order_by(query, [log], asc: log.index)
from(data in sorted_query,
where:
data.index > ^log_index and data.block_number >= ^block_number and
data.transaction_index >= ^transaction_index
)
end
end end

Loading…
Cancel
Save