Fix last_update cache key to store txs count

pull/3330/head
Victor Baranov 4 years ago
parent c25d276d88
commit a7f94afb1a
  1. 2
      apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs
  2. 13
      apps/explorer/lib/explorer/counters/address_transactions_counter.ex

@ -85,7 +85,7 @@ defmodule BlockScoutWeb.AddressControllerTest do
assert conn.status == 200
{:ok, response} = Jason.decode(conn.resp_body)
assert %{"transaction_count" => nil, "validation_count" => 0} == response
assert %{"transaction_count" => 0, "validation_count" => 0} == response
end
end
end

@ -48,7 +48,7 @@ defmodule Explorer.Counters.AddressTransactionsCounter do
end
def fetch(address) do
if cache_expired?() do
if cache_expired?(address) do
Task.start_link(fn ->
update_cache(address)
end)
@ -60,10 +60,9 @@ defmodule Explorer.Counters.AddressTransactionsCounter do
def cache_name, do: @cache_name
def updated_at_key, do: @last_update_key
defp cache_expired? do
updated_at = fetch_from_cache(@last_update_key)
defp cache_expired?(address) do
address_hash_string = get_address_hash_string(address)
updated_at = fetch_from_cache("hash_#{address_hash_string}_#{@last_update_key}")
cond do
is_nil(updated_at) -> true
@ -75,7 +74,7 @@ defmodule Explorer.Counters.AddressTransactionsCounter do
defp update_cache(address) do
new_data = Chain.address_to_transaction_count(address)
address_hash_string = get_address_hash_string(address)
put_into_cache(@last_update_key, current_time())
put_into_cache("hash_#{address_hash_string}_#{@last_update_key}", current_time())
put_into_cache("hash_#{address_hash_string}", new_data)
end
@ -85,7 +84,7 @@ defmodule Explorer.Counters.AddressTransactionsCounter do
value
[] ->
nil
0
end
end

Loading…
Cancel
Save