Skip to content

Commit

Permalink
Merge pull request #2904 from poanetwork/revert-2901-ab-fix-address-s…
Browse files Browse the repository at this point in the history
…um-cache

Revert "fix address sum cache"
  • Loading branch information
vbaranov committed Dec 3, 2019
2 parents 4aa442f + 5333e3c commit d7d242e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
### Features

### Fixes
- [#2901](https://github.com/poanetwork/blockscout/pull/2901) - fix address sum cache

### Chore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ defmodule BlockScoutWeb.API.RPC.StatsControllerTest do

describe "ethsupply" do
test "returns total supply from DB", %{conn: conn} do
insert(:address, fetched_coin_balance: 6)

params = %{
"module" => "stats",
"action" => "ethsupply"
Expand Down
16 changes: 5 additions & 11 deletions apps/explorer/lib/explorer/chain/cache/address_sum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ defmodule Explorer.Chain.Cache.AddressSum do
alias Explorer.Chain

defp handle_fallback(:sum) do
result = fetch_from_db()
# This will get the task PID if one exists and launch a new task if not
# See next `handle_fallback` definition
get_async_task()

if Application.get_env(:explorer, __MODULE__)[:enabled] do
{:update, result}
else
{:return, result}
end
{:return, nil}
end

defp handle_fallback(:async_task) do
Expand All @@ -31,7 +29,7 @@ defmodule Explorer.Chain.Cache.AddressSum do
{:ok, task} =
Task.start(fn ->
try do
result = fetch_from_db()
result = Chain.fetch_sum_coin_total_supply()

set_sum(result)
rescue
Expand All @@ -47,10 +45,6 @@ defmodule Explorer.Chain.Cache.AddressSum do
{:update, task}
end

defp fetch_from_db do
Chain.fetch_sum_coin_total_supply()
end

# By setting this as a `callback` an async task will be started each time the
# `sum` expires (unless there is one already running)
defp async_task_on_deletion({:delete, _, :sum}), do: get_async_task()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Explorer.Chain.Cache.AddressSumTest do
test "returns default address sum" do
result = AddressSum.get_sum()

assert result == 0
assert is_nil(result)
end

test "updates cache if initial value is zero" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule Explorer.Chain.Import.Runner.Address.TokenBalancesTest do
value_fetched_at: DateTime.utc_now()
}

run_changes(new_changes, options)
run_changes(new_changes, options) |> IO.inspect()
end
end

Expand Down

0 comments on commit d7d242e

Please sign in to comment.