Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
goodsoft committed Mar 27, 2019
1 parent 9d1fdd5 commit 5b03ebc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 8 additions & 12 deletions apps/explorer/lib/explorer/chain/import/runner/blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
initial = from(t in Transaction, where: false)

Enum.reduce(blocks_changes, initial, fn %{consensus: consensus, hash: hash, number: number}, acc ->
case consensus do
false ->
from(transaction in acc, or_where: transaction.block_hash == ^hash and transaction.block_number == ^number)

true ->
from(transaction in acc, or_where: transaction.block_hash != ^hash and transaction.block_number == ^number)
if consensus do
from(transaction in acc, or_where: transaction.block_hash != ^hash and transaction.block_number == ^number)
else
from(transaction in acc, or_where: transaction.block_hash == ^hash and transaction.block_number == ^number)
end
end)
end
Expand All @@ -587,12 +585,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
initial = from(b in Block, where: false)

Enum.reduce(blocks_changes, initial, fn %{consensus: consensus, parent_hash: parent_hash, number: number}, acc ->
case consensus do
false ->
acc

true ->
from(block in acc, or_where: block.number == ^(number - 1) and block.hash != ^parent_hash)
if consensus do
from(block in acc, or_where: block.number == ^(number - 1) and block.hash != ^parent_hash)
else
acc
end
end)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
UPDATE blocks SET consensus = FALSE
WHERE number IN (
UPDATE blocks SET consensus = FALSE, updated_at = NOW()
WHERE consensus AND number IN (
SELECT b0.number - 1 FROM "blocks" AS b0
LEFT JOIN "blocks" AS b1 ON (b0."parent_hash" = b1."hash") AND b1."consensus"
WHERE b0."number" > 0 AND b0."consensus" AND b1."hash" IS NULL
Expand Down

0 comments on commit 5b03ebc

Please sign in to comment.