Merge pull request #2888 from poanetwork/ab-remove-pending-op-on-invalidation

remove pending ops on invalidation
vb-address_to_logs_query-performance
Victor Baranov 5 years ago committed by GitHub
commit 2ffda5f1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      apps/explorer/lib/explorer/chain.ex
  2. 4
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  3. 17
      apps/explorer/test/explorer/chain_test.exs
  4. 2
      apps/indexer/lib/indexer/fetcher/internal_transaction.ex

@ -1661,7 +1661,18 @@ defmodule Explorer.Chain do
Repo.stream_reduce(query, initial, reducer) Repo.stream_reduce(query, initial, reducer)
end end
@spec remove_nonconsensus_blocks_from_pending_ops() :: :ok def remove_nonconsensus_blocks_from_pending_ops(block_hashes) do
query =
from(
po in PendingBlockOperation,
where: po.block_hash in ^block_hashes
)
{_, _} = Repo.delete_all(query)
:ok
end
def remove_nonconsensus_blocks_from_pending_ops do def remove_nonconsensus_blocks_from_pending_ops do
query = query =
from( from(

@ -8,7 +8,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
import Ecto.Query, only: [from: 2, subquery: 1] import Ecto.Query, only: [from: 2, subquery: 1]
alias Ecto.{Changeset, Multi, Repo} alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain
alias Explorer.Chain.{Address, Block, Import, Log, PendingBlockOperation, Transaction} alias Explorer.Chain.{Address, Block, Import, Log, PendingBlockOperation, Transaction}
alias Explorer.Chain.Block.Reward alias Explorer.Chain.Block.Reward
alias Explorer.Chain.Import.Runner alias Explorer.Chain.Import.Runner
@ -306,6 +306,8 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
timeout: timeout timeout: timeout
) )
:ok = Chain.remove_nonconsensus_blocks_from_pending_ops(removed_consensus_block_hashes)
{:ok, removed_consensus_block_hashes} {:ok, removed_consensus_block_hashes}
rescue rescue
postgrex_error in Postgrex.Error -> postgrex_error in Postgrex.Error ->

@ -49,6 +49,23 @@ defmodule Explorer.ChainTest do
assert Repo.get(PendingBlockOperation, block.hash) assert Repo.get(PendingBlockOperation, block.hash)
assert is_nil(Repo.get(PendingBlockOperation, nonconsensus_block.hash)) assert is_nil(Repo.get(PendingBlockOperation, nonconsensus_block.hash))
end end
test "removes pending ops for nonconsensus blocks by block hashes" do
block = insert(:block)
insert(:pending_block_operation, block: block, fetch_internal_transactions: true)
nonconsensus_block = insert(:block, consensus: false)
insert(:pending_block_operation, block: nonconsensus_block, fetch_internal_transactions: true)
nonconsensus_block1 = insert(:block, consensus: false)
insert(:pending_block_operation, block: nonconsensus_block1, fetch_internal_transactions: true)
:ok = Chain.remove_nonconsensus_blocks_from_pending_ops([nonconsensus_block1.hash])
assert Repo.get(PendingBlockOperation, block.hash)
assert Repo.get(PendingBlockOperation, nonconsensus_block.hash)
assert is_nil(Repo.get(PendingBlockOperation, nonconsensus_block1.hash))
end
end end
describe "count_addresses_with_balance_from_cache/0" do describe "count_addresses_with_balance_from_cache/0" do

@ -76,8 +76,6 @@ defmodule Indexer.Fetcher.InternalTransaction do
reducer.(block_number, acc) reducer.(block_number, acc)
end) end)
:ok = Chain.remove_nonconsensus_blocks_from_pending_ops()
final final
end end

Loading…
Cancel
Save