diff --git a/lib/explorer_web/controllers/pending_transaction_controller.ex b/lib/explorer_web/controllers/pending_transaction_controller.ex index b3cd76dad1..e56043a4f0 100644 --- a/lib/explorer_web/controllers/pending_transaction_controller.ex +++ b/lib/explorer_web/controllers/pending_transaction_controller.ex @@ -11,11 +11,14 @@ defmodule ExplorerWeb.PendingTransactionController do query = from( transaction in Transaction, - left_join: receipt in assoc(transaction, :receipt), inner_join: to_address in assoc(transaction, :to_address), inner_join: from_address in assoc(transaction, :from_address), preload: [to_address: to_address, from_address: from_address], - where: is_nil(receipt.transaction_id), + where: + fragment( + "NOT EXISTS (SELECT true FROM receipts WHERE receipts.transaction_id = ?)", + transaction.id + ), where: transaction.id < ^last_seen, order_by: [desc: transaction.id], limit: 10 @@ -24,8 +27,11 @@ defmodule ExplorerWeb.PendingTransactionController do total_query = from( transaction in Transaction, - left_join: receipt in assoc(transaction, :receipt), - where: is_nil(receipt.transaction_id), + where: + fragment( + "NOT EXISTS (SELECT true FROM receipts WHERE receipts.transaction_id = ?)", + transaction.id + ), order_by: [desc: transaction.id], limit: 1 ) @@ -55,8 +61,11 @@ defmodule ExplorerWeb.PendingTransactionController do from( transaction in Transaction, select: transaction.id, - left_join: receipt in assoc(transaction, :receipt), - where: is_nil(receipt.transaction_id), + where: + fragment( + "NOT EXISTS (SELECT true FROM receipts WHERE receipts.transaction_id = ?)", + transaction.id + ), order_by: [desc: transaction.id], limit: 1 )