Merge pull request #2915 from poanetwork/vb-speedup-blocks_without_reward_query

Speedup of blocks_without_reward_query
pull/2932/head
Victor Baranov 5 years ago committed by GitHub
commit 67f9a3c1c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 16
      apps/explorer/lib/explorer/chain/block.ex
  3. 9
      apps/explorer/priv/repo/migrations/20191208135613_block_rewards_block_hash_partial_index.exs

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

@ -116,11 +116,23 @@ defmodule Explorer.Chain.Block do
end
def blocks_without_reward_query do
consensus_blocks_query =
from(
b in __MODULE__,
left_join: r in Reward,
where: b.consensus == true
)
validator_rewards =
from(
r in Reward,
where: r.address_type == ^"validator"
)
from(
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

@ -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
Loading…
Cancel
Save