diff --git a/CHANGELOG.md b/CHANGELOG.md index c72a4798de..67d0f340c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#2918](https://github.com/poanetwork/blockscout/pull/2918) - Add tokenID for tokentx API action ### Fixes +- [#2915](https://github.com/poanetwork/blockscout/pull/2915) - Speedup of blocks_without_reward_query - [#2914](https://github.com/poanetwork/blockscout/pull/2914) - Reduce execution time of stream_unfetched_token_instances query - [#2906](https://github.com/poanetwork/blockscout/pull/2906) - fix address sum cache - [#2902](https://github.com/poanetwork/blockscout/pull/2902) - Offset in blocks retrieval for average block time diff --git a/apps/explorer/lib/explorer/chain/block.ex b/apps/explorer/lib/explorer/chain/block.ex index 32905cf076..83aecafa9f 100644 --- a/apps/explorer/lib/explorer/chain/block.ex +++ b/apps/explorer/lib/explorer/chain/block.ex @@ -116,11 +116,23 @@ defmodule Explorer.Chain.Block do end def blocks_without_reward_query do + consensus_blocks_query = + from( + b in __MODULE__, + where: b.consensus == true + ) + + validator_rewards = + from( + r in Reward, + where: r.address_type == ^"validator" + ) + from( - b in __MODULE__, - left_join: r in Reward, + b in subquery(consensus_blocks_query), + left_join: r in subquery(validator_rewards), on: [block_hash: b.hash], - where: is_nil(r.block_hash) and b.consensus == true + where: is_nil(r.block_hash) ) end diff --git a/apps/explorer/priv/repo/migrations/20191208135613_block_rewards_block_hash_partial_index.exs b/apps/explorer/priv/repo/migrations/20191208135613_block_rewards_block_hash_partial_index.exs new file mode 100644 index 0000000000..0b0fa86a4a --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20191208135613_block_rewards_block_hash_partial_index.exs @@ -0,0 +1,9 @@ +defmodule Explorer.Repo.Migrations.BlockRewardsBlockHashPartialIndex do + use Ecto.Migration + + def change do + execute( + "CREATE INDEX IF NOT EXISTS block_rewards_block_hash_partial_index on block_rewards(block_hash) WHERE address_type='validator';" + ) + end +end