|
|
@ -40,15 +40,10 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def init(args) do |
|
|
|
def init(_args) do |
|
|
|
create_table() |
|
|
|
create_table() |
|
|
|
|
|
|
|
|
|
|
|
if enable_consolidation?() do |
|
|
|
{:ok, %{consolidate?: enable_consolidation?()}, {:continue, :ok}} |
|
|
|
Task.start_link(&consolidate/0) |
|
|
|
|
|
|
|
schedule_next_consolidation() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, args} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def create_table do |
|
|
|
def create_table do |
|
|
@ -63,9 +58,7 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp schedule_next_consolidation do |
|
|
|
defp schedule_next_consolidation do |
|
|
|
if enable_consolidation?() do |
|
|
|
Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) |
|
|
|
Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -75,6 +68,19 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do |
|
|
|
:ets.insert(table_name(), {key, info}) |
|
|
|
:ets.insert(table_name(), {key, info}) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
|
|
|
|
def handle_continue(:ok, %{consolidate?: true} = state) do |
|
|
|
|
|
|
|
consolidate() |
|
|
|
|
|
|
|
schedule_next_consolidation() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:noreply, state} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
|
|
|
|
def handle_continue(:ok, state) do |
|
|
|
|
|
|
|
{:noreply, state} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def handle_info(:consolidate, state) do |
|
|
|
def handle_info(:consolidate, state) do |
|
|
|
consolidate() |
|
|
|
consolidate() |
|
|
|