Convert 99% of int txs indexing into 1.0 in order to hide top indexing banner

pull/7276/head
Viktor Baranov 2 years ago
parent 98cd1cfa6d
commit 36ccff99ee
  1. 1
      CHANGELOG.md
  2. 83
      apps/explorer/lib/explorer/chain.ex

@ -7,6 +7,7 @@
### Fixes
- [#7270](https://github.com/blockscout/blockscout/pull/7270) - Fix default `TOKEN_EXCHANGE_RATE_REFETCH_INTERVAL`
- [#7276](https://github.com/blockscout/blockscout/pull/7276) - Convert 99+% of int txs indexing into 100% in order to hide top indexing banner
### Chore

@ -2229,33 +2229,24 @@ defmodule Explorer.Chain do
@spec indexed_ratio_blocks() :: Decimal.t()
def indexed_ratio_blocks do
if Application.get_env(:indexer, Indexer.Supervisor)[:enabled] do
%{min: min, max: max} = BlockNumber.get_all()
%{min: min_saved_block_number, max: max_saved_block_number} = BlockNumber.get_all()
min_blockchain_block_number =
case Integer.parse(Application.get_env(:indexer, :first_block)) do
{block_number, _} -> block_number
_ -> 0
end
min_blockchain_block_number = min_block_number_from_config(:first_block)
case {min, max} do
case {min_saved_block_number, max_saved_block_number} do
{0, 0} ->
Decimal.new(0)
_ ->
result =
BlockCache.estimated_count()
|> Decimal.div(max - min_blockchain_block_number + 1)
|> (&if(
(Decimal.compare(&1, Decimal.from_float(0.99)) == :gt ||
Decimal.compare(&1, Decimal.from_float(0.99)) == :eq) &&
min <= min_blockchain_block_number,
do: Decimal.new(1),
else: &1
)).()
result
|> Decimal.round(2, :down)
|> Decimal.min(Decimal.new(1))
BlockCache.estimated_count()
|> Decimal.div(max_saved_block_number - min_blockchain_block_number + 1)
|> (&if(
greater_or_equal_0_99(&1) &&
min_saved_block_number <= min_blockchain_block_number,
do: Decimal.new(1),
else: &1
)).()
|> format_indexed_ratio()
end
else
Decimal.new(1)
@ -2266,32 +2257,54 @@ defmodule Explorer.Chain do
def indexed_ratio_internal_transactions do
if Application.get_env(:indexer, Indexer.Supervisor)[:enabled] &&
not Application.get_env(:indexer, Indexer.Fetcher.InternalTransaction.Supervisor)[:disabled?] do
%{max: max} = BlockNumber.get_all()
count = Repo.aggregate(PendingBlockOperation, :count, timeout: :infinity)
%{max: max_saved_block_number} = BlockNumber.get_all()
pbo_count = Repo.aggregate(PendingBlockOperation, :count, timeout: :infinity)
min_blockchain_trace_block_number =
case Integer.parse(Application.get_env(:indexer, :trace_first_block)) do
{block_number, _} -> block_number
_ -> 0
end
min_blockchain_trace_block_number = min_block_number_from_config(:trace_first_block)
case max do
case max_saved_block_number do
0 ->
Decimal.new(0)
_ ->
full_blocks_range = max - min_blockchain_trace_block_number + 1
result = Decimal.div(full_blocks_range - count, full_blocks_range)
result
|> Decimal.round(2, :down)
|> Decimal.min(Decimal.new(1))
full_blocks_range = max_saved_block_number - min_blockchain_trace_block_number + 1
processed_int_txs_for_blocks_count = full_blocks_range - pbo_count
processed_int_txs_for_blocks_count
|> Decimal.div(full_blocks_range)
|> (&if(
greater_or_equal_0_99(&1),
do: Decimal.new(1),
else: &1
)).()
|> format_indexed_ratio()
end
else
Decimal.new(1)
end
end
@spec greater_or_equal_0_99(Decimal.t()) :: boolean()
defp greater_or_equal_0_99(value) do
Decimal.compare(value, Decimal.from_float(0.99)) == :gt ||
Decimal.compare(value, Decimal.from_float(0.99)) == :eq
end
@spec min_block_number_from_config(atom()) :: integer()
defp min_block_number_from_config(block_type) do
case Integer.parse(Application.get_env(:indexer, block_type)) do
{block_number, _} -> block_number
_ -> 0
end
end
@spec format_indexed_ratio(Decimal.t()) :: Decimal.t()
defp format_indexed_ratio(raw_ratio) do
raw_ratio
|> Decimal.round(2, :down)
|> Decimal.min(Decimal.new(1))
end
@spec fetch_min_block_number() :: non_neg_integer
def fetch_min_block_number do
query =

Loading…
Cancel
Save