From 1015bfd0a4432d2d39b580c35b617cbfe3daa5dd Mon Sep 17 00:00:00 2001 From: nikitosing <32202610+nikitosing@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:23:15 +0300 Subject: [PATCH] fix: Fix slow internal transactions query (#10346) --- apps/explorer/lib/explorer/chain/internal_transaction.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/internal_transaction.ex b/apps/explorer/lib/explorer/chain/internal_transaction.ex index 0678dfc97f..793a7fc65e 100644 --- a/apps/explorer/lib/explorer/chain/internal_transaction.ex +++ b/apps/explorer/lib/explorer/chain/internal_transaction.ex @@ -576,8 +576,10 @@ defmodule Explorer.Chain.InternalTransaction do """ def where_nonpending_block(query \\ nil) do (query || __MODULE__) - |> join(:left, [it], pending in assoc(it, :pending_block), as: :pending) - |> where([it, pending: pending], is_nil(pending.block_hash)) + |> where( + [it], + fragment("(SELECT block_hash FROM pending_block_operations WHERE block_hash = ? LIMIT 1) IS NULL", it.block_hash) + ) end def internal_transactions_to_raw(internal_transactions) when is_list(internal_transactions) do