From 7afe8e19b59923ac4bf1b065c6e3a0f0a0ed9d45 Mon Sep 17 00:00:00 2001 From: Qwerty5Uiop Date: Fri, 21 Jul 2023 14:10:46 +0400 Subject: [PATCH] Add CoinBalance fetcher init query limit --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/chain.ex | 10 +++++++++- apps/indexer/lib/indexer/fetcher/coin_balance.ex | 3 ++- config/runtime.exs | 4 +++- docker-compose/envs/common-blockscout.env | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a707ea381..649eee4110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - [#8180](https://github.com/blockscout/blockscout/pull/8180) - Deposits and Withdrawals for Polygon Edge +- [#7996](https://github.com/blockscout/blockscout/pull/7996) - Add CoinBalance fetcher init query limit ### Fixes diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 3c4239b7ce..6aa532de03 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2232,7 +2232,7 @@ defmodule Explorer.Chain do ) query - |> add_fetcher_limit(limited?) + |> add_coin_balances_fetcher_limit(limited?) |> Repo.stream_reduce(initial, reducer) end @@ -6315,6 +6315,14 @@ defmodule Explorer.Chain do limit(query, ^token_balances_fetcher_limit) end + defp add_coin_balances_fetcher_limit(query, false), do: query + + defp add_coin_balances_fetcher_limit(query, true) do + coin_balances_fetcher_limit = Application.get_env(:indexer, :coin_balances_fetcher_init_limit) + + limit(query, ^coin_balances_fetcher_limit) + end + def put_has_token_transfers_to_tx(query, true), do: query def put_has_token_transfers_to_tx(query, false) do diff --git a/apps/indexer/lib/indexer/fetcher/coin_balance.ex b/apps/indexer/lib/indexer/fetcher/coin_balance.ex index ce80805e5d..26d5d39962 100644 --- a/apps/indexer/lib/indexer/fetcher/coin_balance.ex +++ b/apps/indexer/lib/indexer/fetcher/coin_balance.ex @@ -69,7 +69,8 @@ defmodule Indexer.Fetcher.CoinBalance do address_fields |> entry() |> reducer.(acc) - end + end, + true ) final diff --git a/config/runtime.exs b/config/runtime.exs index 54b268988f..2d51abb619 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -431,7 +431,9 @@ config :indexer, hide_indexing_progress_alert: ConfigHelper.parse_bool_env_var("INDEXER_HIDE_INDEXING_PROGRESS_ALERT"), fetcher_init_limit: ConfigHelper.parse_integer_env_var("INDEXER_FETCHER_INIT_QUERY_LIMIT", 100), token_balances_fetcher_init_limit: - ConfigHelper.parse_integer_env_var("INDEXER_TOKEN_BALANCES_FETCHER_INIT_QUERY_LIMIT", 100_000) + ConfigHelper.parse_integer_env_var("INDEXER_TOKEN_BALANCES_FETCHER_INIT_QUERY_LIMIT", 100_000), + coin_balances_fetcher_init_limit: + ConfigHelper.parse_integer_env_var("INDEXER_COIN_BALANCES_FETCHER_INIT_QUERY_LIMIT", 2000) config :indexer, Indexer.Supervisor, enabled: !ConfigHelper.parse_bool_env_var("DISABLE_INDEXER") diff --git a/docker-compose/envs/common-blockscout.env b/docker-compose/envs/common-blockscout.env index 39ad8823cd..5d8c29b3c5 100644 --- a/docker-compose/envs/common-blockscout.env +++ b/docker-compose/envs/common-blockscout.env @@ -139,6 +139,7 @@ INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false # INDEXER_REALTIME_FETCHER_MAX_GAP= # INDEXER_FETCHER_INIT_QUERY_LIMIT= # INDEXER_TOKEN_BALANCES_FETCHER_INIT_QUERY_LIMIT= +# INDEXER_COIN_BALANCES_FETCHER_INIT_QUERY_LIMIT= # INDEXER_DISABLE_WITHDRAWALS_FETCHER= # WITHDRAWALS_FIRST_BLOCK= # TOKEN_ID_MIGRATION_FIRST_BLOCK=