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).
pull/2267/head
pasqu4le 5 years ago
parent 3c6abf4d23
commit 453d04244e
No known key found for this signature in database
GPG Key ID: 8F3EE01F1DC90687
  1. 1
      CHANGELOG.md
  2. 10
      apps/explorer/lib/explorer/chain.ex

@ -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

@ -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

Loading…
Cancel
Save