From 0a32431f2045f0d1a5b02326e4a08b222d32f204 Mon Sep 17 00:00:00 2001 From: zachdaniel Date: Mon, 20 May 2019 16:46:11 -0400 Subject: [PATCH] fix: consolidate address w/ balance one at a time --- CHANGELOG.md | 1 + .../addresses_with_balance_counter.ex | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e60b218c2..8d193835fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - [#1956](https://github.com/poanetwork/blockscout/pull/1956) - add logs tab to address - [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method - [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default +- [#1989](https://github.com/poanetwork/blockscout/pull/1989) - fix: consolidate address w/ balance one at a time ### Fixes diff --git a/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex b/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex index 3a03a7bcd5..cdc2530f93 100644 --- a/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex +++ b/apps/explorer/lib/explorer/counters/addresses_with_balance_counter.ex @@ -40,15 +40,10 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do end @impl true - def init(args) do + def init(_args) do create_table() - if enable_consolidation?() do - Task.start_link(&consolidate/0) - schedule_next_consolidation() - end - - {:ok, args} + {:ok, %{consolidate?: enable_consolidation?()}, {:continue, :ok}} end def create_table do @@ -63,9 +58,7 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do end defp schedule_next_consolidation do - if enable_consolidation?() do - Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) - end + Process.send_after(self(), :consolidate, :timer.seconds(@update_interval_in_seconds)) end @doc """ @@ -75,6 +68,19 @@ defmodule Explorer.Counters.AddressesWithBalanceCounter do :ets.insert(table_name(), {key, info}) 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 def handle_info(:consolidate, state) do consolidate()