Order current token balance inserts to prevent deadlock

Fixes #1295
pull/1296/head
Luke Imhoff 6 years ago
parent b69d437b06
commit df8673242e
  1. 5
      apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex

@ -60,10 +60,13 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalances do
when is_atom(repo) and is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
# order so that row ShareLocks are grabbed in a consistent order
ordered_changes_list = Enum.sort_by(changes_list, &{&1.address_hash, &1.token_contract_address_hash})
{:ok, _} =
Import.insert_changes_list(
repo,
changes_list,
ordered_changes_list,
conflict_target: ~w(address_hash token_contract_address_hash)a,
on_conflict: on_conflict,
for: CurrentTokenBalance,

Loading…
Cancel
Save