From ac166adac926c5a4e1605c2f363911b6c6eca76e Mon Sep 17 00:00:00 2001 From: Stamates Date: Tue, 7 Aug 2018 10:52:06 -0400 Subject: [PATCH] Remove unused Chain.address_count function and format/credo appeasement --- apps/explorer/lib/explorer/chain.ex | 24 +++---------------- apps/explorer_web/assets/js/pages/chain.js | 4 ++-- .../explorer_web/channels/address_channel.ex | 2 +- .../controllers/chain_controller.ex | 3 +-- .../explorer_web/lib/explorer_web/notifier.ex | 2 +- .../features/viewing_chain_test.exs | 3 ++- .../explorer_web/test/support/fake_adapter.ex | 2 +- 7 files changed, 11 insertions(+), 29 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 8d94dee0ff..12da6c602e 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -69,7 +69,7 @@ defmodule Explorer.Chain do Estimated count of addresses """ - @spec address_estimated_count() :: non_neg_integer() + @spec address_estimated_count :: non_neg_integer() def address_estimated_count do %Postgrex.Result{rows: [[rows]]} = SQL.query!(Repo, "SELECT reltuples::BIGINT AS estimate FROM pg_class WHERE relname='addresses'") @@ -188,12 +188,11 @@ defmodule Explorer.Chain do |> Repo.all() end - @doc """ The average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` """ - @spec average_block_time() :: non_neg_integer() - def average_block_time() do + @spec average_block_time :: %Timex.Duration{} + def average_block_time do {:ok, %Postgrex.Result{rows: [[rows]]}} = SQL.query( Repo, @@ -652,23 +651,6 @@ defmodule Explorer.Chain do Import.all(options) end - @doc """ - The number of `t:Explorer.Chain.Address.t/0`. - - iex> insert_list(2, :address) - iex> Explorer.Chain.address_count() - 2 - - When there are no `t:Explorer.Chain.Address.t/0`, the count is `0`. - - iex> Explorer.Chain.address_count() - 0 - - """ - def address_count do - Repo.aggregate(Address, :count, :hash) - end - @doc """ The number of `t:Explorer.Chain.InternalTransaction.t/0`. diff --git a/apps/explorer_web/assets/js/pages/chain.js b/apps/explorer_web/assets/js/pages/chain.js index 62c3ebc44e..364f1bfe6a 100644 --- a/apps/explorer_web/assets/js/pages/chain.js +++ b/apps/explorer_web/assets/js/pages/chain.js @@ -88,10 +88,10 @@ router.when('', { exactPathMatch: true }).then(({ locale }) => initRedux(reducer const $transactionCount = $('[data-selector="transaction-count"]') if (oldState.addressCount !== state.addressCount) { - $addressCount.empty().append(state.addressCount) + $addressCount.empty().append(state.addressCount) } if (oldState.averageBlockTime !== state.averageBlockTime) { - $averageBlockTime.empty().append(state.averageBlockTime) + $averageBlockTime.empty().append(state.averageBlockTime) } if (oldState.newBlock !== state.newBlock) { $blockList.children().last().remove() diff --git a/apps/explorer_web/lib/explorer_web/channels/address_channel.ex b/apps/explorer_web/lib/explorer_web/channels/address_channel.ex index 8a4806e8a2..1c24c8d706 100644 --- a/apps/explorer_web/lib/explorer_web/channels/address_channel.ex +++ b/apps/explorer_web/lib/explorer_web/channels/address_channel.ex @@ -40,7 +40,7 @@ defmodule ExplorerWeb.AddressChannel do {:noreply, socket} end - + def handle_out("transaction", %{address: address, transaction: transaction}, socket) do Gettext.put_locale(ExplorerWeb.Gettext, socket.assigns.locale) diff --git a/apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex b/apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex index 51ccb85e30..7dc10c9cbd 100644 --- a/apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex +++ b/apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex @@ -1,8 +1,7 @@ defmodule ExplorerWeb.ChainController do use ExplorerWeb, :controller - alias Explorer.{PagingOptions, Repo} - alias Explorer.Chain + alias Explorer.{Chain, PagingOptions, Repo} alias Explorer.Chain.{Address, Block, Transaction} alias Explorer.ExchangeRates.Token alias Explorer.Market diff --git a/apps/explorer_web/lib/explorer_web/notifier.ex b/apps/explorer_web/lib/explorer_web/notifier.ex index 1bb0164619..9d122dc4f6 100644 --- a/apps/explorer_web/lib/explorer_web/notifier.ex +++ b/apps/explorer_web/lib/explorer_web/notifier.ex @@ -48,7 +48,7 @@ defmodule ExplorerWeb.Notifier do Endpoint.broadcast("blocks:new_block", "new_block", %{ block: preloaded_block, average_block_time: Chain.average_block_time() - }) + }) end defp broadcast_transaction(transaction) do diff --git a/apps/explorer_web/test/explorer_web/features/viewing_chain_test.exs b/apps/explorer_web/test/explorer_web/features/viewing_chain_test.exs index ae4abe36d9..fbafc9c0c6 100644 --- a/apps/explorer_web/test/explorer_web/features/viewing_chain_test.exs +++ b/apps/explorer_web/test/explorer_web/features/viewing_chain_test.exs @@ -30,6 +30,7 @@ defmodule ExplorerWeb.ViewingChainTest do describe "statistics" do test "average block time live updates", %{session: session} do time = DateTime.utc_now() + for x <- 100..0 do insert(:block, timestamp: Timex.shift(time, seconds: -5 * x), number: x + 500) end @@ -40,7 +41,7 @@ defmodule ExplorerWeb.ViewingChainTest do block = 100..0 - |> Enum.map(fn(index) -> + |> Enum.map(fn index -> insert(:block, timestamp: Timex.shift(time, seconds: -10 * index), number: index + 800) end) |> hd() diff --git a/apps/explorer_web/test/support/fake_adapter.ex b/apps/explorer_web/test/support/fake_adapter.ex index b9d8ff0397..b92b353557 100644 --- a/apps/explorer_web/test/support/fake_adapter.ex +++ b/apps/explorer_web/test/support/fake_adapter.ex @@ -2,7 +2,7 @@ defmodule ExplorerWeb.FakeAdapter do alias Explorer.Chain.Address alias Explorer.Repo - def address_estimated_count() do + def address_estimated_count do Repo.aggregate(Address, :count, :hash) end end