From f354a1e9f4812cc8bbb5a36bf031ff58c67745c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F=D0=BA=D0=BE=D0=B2?= Date: Fri, 25 Nov 2022 15:18:40 +0300 Subject: [PATCH] Split ordering cases for txs --- apps/explorer/lib/explorer/chain.ex | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 2ccb300b3e..a731bdea16 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -439,7 +439,7 @@ defmodule Explorer.Chain do options |> Keyword.get(:paging_options, @default_paging_options) - |> fetch_transactions(from_block, to_block) + |> fetch_transactions(from_block, to_block, true) end defp transactions_block_numbers_at_address(address_hash, options) do @@ -4383,16 +4383,36 @@ defmodule Explorer.Chain do if Repo.one(query), do: true, else: false end - defp fetch_transactions(paging_options \\ nil, from_block \\ nil, to_block \\ nil) do + defp fetch_transactions(paging_options \\ nil, from_block \\ nil, to_block \\ nil, is_address? \\ false) do Transaction + |> order_for_transactions(paging_options, is_address?) + |> where_block_number_in_period(from_block, to_block) + |> handle_paging_options(paging_options) + end + + defp order_for_transactions(query, %PagingOptions{is_pending_tx: true}, true) do + query |> order_by([transaction], desc: transaction.block_number, desc: transaction.index, desc: transaction.inserted_at, desc: transaction.hash ) - |> where_block_number_in_period(from_block, to_block) - |> handle_paging_options(paging_options) + end + + defp order_for_transactions(query, %PagingOptions{key: nil}, true) do + query + |> order_by([transaction], + desc: transaction.block_number, + desc: transaction.index, + desc: transaction.inserted_at, + desc: transaction.hash + ) + end + + defp order_for_transactions(query, _, _) do + query + |> order_by([transaction], desc: transaction.block_number, desc: transaction.index) end defp fetch_transactions_in_ascending_order_by_index(paging_options) do