Delete invalid current token balances in OnDemand fetcher

pull/8924/head
Qwerty5Uiop 12 months ago
parent 0de31b220f
commit c0ca7081d8
  1. 2
      CHANGELOG.md
  2. 9
      apps/indexer/lib/indexer/fetcher/token_balance_on_demand.ex

@ -2,6 +2,8 @@
## Current
- [#8924](https://github.com/blockscout/blockscout/pull/8924) - Delete invalid current token balances in OnDemand fetcher
### Features
### Fixes

@ -6,7 +6,7 @@ defmodule Indexer.Fetcher.TokenBalanceOnDemand do
use Indexer.Fetcher
alias Explorer.Chain
alias Explorer.{Chain, Repo}
alias Explorer.Chain.Address.CurrentTokenBalance
alias Explorer.Chain.Cache.BlockNumber
alias Explorer.Chain.Events.Publisher
@ -52,6 +52,7 @@ defmodule Indexer.Fetcher.TokenBalanceOnDemand do
stale_current_token_balances =
address_hash
|> Chain.fetch_last_token_balances_include_unfetched()
|> delete_invalid_balances()
|> Enum.filter(fn current_token_balance -> current_token_balance.block_number < stale_balance_window end)
if Enum.count(stale_current_token_balances) > 0 do
@ -63,6 +64,12 @@ defmodule Indexer.Fetcher.TokenBalanceOnDemand do
:ok
end
defp delete_invalid_balances(current_token_balances) do
{invalid_balances, valid_balances} = Enum.split_with(current_token_balances, &is_nil(&1.token_type))
Enum.each(invalid_balances, &Repo.delete/1)
valid_balances
end
defp fetch_and_update(block_number, address_hash, stale_current_token_balances) do
%{erc_1155: erc_1155_ctbs, other: other_ctbs, tokens: tokens} =
stale_current_token_balances

Loading…
Cancel
Save