add index for pending transaction ordering

pull/2155/head
Ayrat Badykov 6 years ago
parent 0729dca908
commit 05a98ef164
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 3
      apps/explorer/lib/explorer/chain.ex
  2. 7
      apps/explorer/priv/repo/migrations/20190613065856_add_tx_hash_inserted_at_index.exs

@ -1987,7 +1987,6 @@ defmodule Explorer.Chain do
|> page_pending_transaction(paging_options) |> page_pending_transaction(paging_options)
|> limit(^paging_options.page_size) |> limit(^paging_options.page_size)
|> pending_transactions_query() |> pending_transactions_query()
|> where([transaction], is_nil(transaction.error) or transaction.error != "dropped/replaced")
|> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash) |> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash)
|> join_associations(necessity_by_association) |> join_associations(necessity_by_association)
|> preload([{:token_transfers, [:token, :from_address, :to_address]}]) |> preload([{:token_transfers, [:token, :from_address, :to_address]}])
@ -1996,7 +1995,7 @@ defmodule Explorer.Chain do
defp pending_transactions_query(query) do defp pending_transactions_query(query) do
from(transaction in query, from(transaction in query,
where: is_nil(transaction.block_hash) where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced")
) )
end end

@ -0,0 +1,7 @@
defmodule Explorer.Repo.Migrations.AddTxHashInsertedAtIndex do
use Ecto.Migration
def change do
create index(:transactions, [:hash, :inserted_at])
end
end
Loading…
Cancel
Save