Merge pull request #4535 from blockscout/vb-tt-updater-fix

Indexer performance update: Eliminate multiple updates of the same token while parsing mint/burn token transfers batch
pull/4542/head
Victor Baranov 3 years ago committed by GitHub
commit ba5e4da467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 53
      apps/indexer/lib/indexer/transform/token_transfers.ex

@ -8,6 +8,7 @@
- [#4452](https://github.com/blockscout/blockscout/pull/4452) - Add names for smart-conrtact's function response
### Fixes
- [#4535](https://github.com/blockscout/blockscout/pull/4535) - Indexer performance update:: Eliminate multiple updates of the same token while parsing mint/burn token transfers batch
- [#4527](https://github.com/blockscout/blockscout/pull/4527) - Indexer performance update: refactor coin balance daily fetcher
- [#4525](https://github.com/blockscout/blockscout/pull/4525) - Uncataloged token transfers query performance improvement
- [#4513](https://github.com/blockscout/blockscout/pull/4513) - Fix installation with custom default path: add NETWORK_PATH variable to the current_path

@ -18,9 +18,24 @@ defmodule Indexer.Transform.TokenTransfers do
def parse(logs) do
initial_acc = %{tokens: [], token_transfers: []}
logs
|> Enum.filter(&(&1.first_topic == unquote(TokenTransfer.constant())))
|> Enum.reduce(initial_acc, &do_parse/2)
token_transfers_from_logs =
logs
|> Enum.filter(&(&1.first_topic == unquote(TokenTransfer.constant())))
|> Enum.reduce(initial_acc, &do_parse/2)
token_transfers = token_transfers_from_logs.token_transfers
token_transfers
|> Enum.filter(fn token_transfer ->
token_transfer.to_address_hash == @burn_address || token_transfer.from_address_hash == @burn_address
end)
|> Enum.map(fn token_transfer ->
token_transfer.token_contract_address_hash
end)
|> Enum.dedup()
|> Enum.each(&update_token/1)
token_transfers_from_logs
end
defp do_parse(log, %{tokens: tokens, token_transfers: token_transfers} = acc) do
@ -58,8 +73,6 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-20"
}
update_token(log.address_hash, token_transfer)
{token, token_transfer}
end
@ -85,8 +98,6 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-721"
}
update_token(log.address_hash, token_transfer)
{token, token_transfer}
end
@ -112,28 +123,26 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-721"
}
update_token(log.address_hash, token_transfer)
{token, token_transfer}
end
defp update_token(address_hash_string, token_transfer) do
if token_transfer.to_address_hash == @burn_address || token_transfer.from_address_hash == @burn_address do
{:ok, address_hash} = Chain.string_to_address_hash(address_hash_string)
defp update_token(nil), do: :ok
defp update_token(address_hash_string) do
{:ok, address_hash} = Chain.string_to_address_hash(address_hash_string)
token_params =
address_hash_string
|> MetadataRetriever.get_functions_of()
token_params =
address_hash_string
|> MetadataRetriever.get_functions_of()
token = Repo.get_by(Token, contract_address_hash: address_hash)
token = Repo.get_by(Token, contract_address_hash: address_hash)
if token do
token_to_update =
token
|> Repo.preload([:contract_address])
if token do
token_to_update =
token
|> Repo.preload([:contract_address])
{:ok, _} = Chain.update_token(%{token_to_update | updated_at: DateTime.utc_now()}, token_params)
end
{:ok, _} = Chain.update_token(%{token_to_update | updated_at: DateTime.utc_now()}, token_params)
end
:ok

Loading…
Cancel
Save