From 4614878507f523746fc9d1ab304e896a6f5b655c Mon Sep 17 00:00:00 2001 From: Nikita Pozdniakov Date: Fri, 20 Oct 2023 12:23:44 +0300 Subject: [PATCH] Process review comments --- apps/explorer/lib/explorer/chain/address/counters.ex | 11 ++++++++++- .../explorer/chain/cache/addresses_tabs_counters.ex | 10 +++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/address/counters.ex b/apps/explorer/lib/explorer/chain/address/counters.ex index 71b11b078d..9f0aea47d8 100644 --- a/apps/explorer/lib/explorer/chain/address/counters.ex +++ b/apps/explorer/lib/explorer/chain/address/counters.ex @@ -245,7 +245,7 @@ defmodule Explorer.Chain.Address.Counters do end end - def address_hash_to_internal_txs_limited_count_query(address_hash) do + defp address_hash_to_internal_txs_limited_count_query(address_hash) do query_to_address_hash_wrapped = InternalTransaction |> InternalTransaction.where_nonpending_block() @@ -570,6 +570,15 @@ defmodule Explorer.Chain.Address.Counters do end) end + @doc """ + Returns all possible transactions type + """ + @spec txs_types :: list(atom) def txs_types, do: @txs_types + + @doc """ + Returns max counter value + """ + @spec counters_limit :: integer() def counters_limit, do: @counters_limit end diff --git a/apps/explorer/lib/explorer/chain/cache/addresses_tabs_counters.ex b/apps/explorer/lib/explorer/chain/cache/addresses_tabs_counters.ex index 00aaf5c64f..ab79fbf0a5 100644 --- a/apps/explorer/lib/explorer/chain/cache/addresses_tabs_counters.ex +++ b/apps/explorer/lib/explorer/chain/cache/addresses_tabs_counters.ex @@ -27,18 +27,22 @@ defmodule Explorer.Chain.Cache.AddressesTabsCounters do :ok end + @spec set_task(atom, String.t()) :: true def set_task(counter_type, address_hash) do :ets.insert(@cache_name, {task_cache_key(address_hash, counter_type), true}) end + @spec drop_task(atom, String.t()) :: true def drop_task(counter_type, address_hash) do :ets.delete(@cache_name, task_cache_key(address_hash, counter_type)) end + @spec get_task(atom, String.t()) :: true | nil def get_task(counter_type, address_hash) do address_hash |> task_cache_key(counter_type) |> fetch_from_cache(@cache_name, nil) end + @spec ignore_txs(atom, String.t()) :: :ignore | :ok def ignore_txs(:txs, address_hash), do: GenServer.cast(__MODULE__, {:ignore_txs, address_hash}) def ignore_txs(_counter_type, _address_hash), do: :ignore @@ -103,10 +107,10 @@ defmodule Explorer.Chain.Cache.AddressesTabsCounters do defp is_ignored?({:updated, datetime}), do: is_up_to_date?(datetime, ttl()) defp is_ignored?(_), do: false - def check_staleness(nil), do: nil - def check_staleness({datetime, counter}) when counter > 50, do: {datetime, counter, :limit_value} + defp check_staleness(nil), do: nil + defp check_staleness({datetime, counter}) when counter > 50, do: {datetime, counter, :limit_value} - def check_staleness({datetime, counter}) do + defp check_staleness({datetime, counter}) do status = if is_up_to_date?(datetime, ttl()) do :up_to_date