From 453d04244ef57a46d1824cdea75d0aec95e3ae20 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 28 Jun 2019 13:56:54 +0200 Subject: [PATCH] Modify the implementation of `Explorer.Chain.where_transaction_has_multiple_internal_transactions` Problem: the implementation of that `WHERE` filter is too inefficient. In particular this was brought to attention because it causes `Explorer.Etherscan.list_internal_transactions/2` to timeout for some addresses. (For example: address `0x1B3858E01CCE5d0491f3c96A9996a65607f3493b`) Solution: while keeping the same result the previous check for siblings (SELECT/LIMIT 2/COUNT/(> 1)) has been replaced by a less expensive one that better uses the existing indexes (EXISTS/index comparison). --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain.ex | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5466e53feb..90b064fc92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ - [#2204](https://github.com/poanetwork/blockscout/pull/2204) - fix large contract verification - [#2247](https://github.com/poanetwork/blockscout/pull/2247) - hide logs search if there are no logs - [#2248](https://github.com/poanetwork/blockscout/pull/2248) - sort block after query execution for average block time +- [#2267](https://github.com/poanetwork/blockscout/pull/2267) - Modify implementation of `where_transaction_has_multiple_internal_transactions` ### Chore - [#2127](https://github.com/poanetwork/blockscout/pull/2127) - use previouse chromedriver version diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e4416030b0..e3db14b2a1 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2580,14 +2580,14 @@ defmodule Explorer.Chain do internal_transaction.type != ^:call or fragment( """ - (SELECT COUNT(sibling.*) + EXISTS (SELECT sibling.* FROM internal_transactions AS sibling - WHERE sibling.transaction_hash = ? - LIMIT 2 + WHERE sibling.transaction_hash = ? AND sibling.index != ? ) """, - transaction.hash - ) > 1 + transaction.hash, + internal_transaction.index + ) ) end