Remove unused Chain.address_count function and format/credo appeasement

pull/511/head
Stamates 6 years ago
parent 36949da03b
commit ac166adac9
  1. 24
      apps/explorer/lib/explorer/chain.ex
  2. 4
      apps/explorer_web/assets/js/pages/chain.js
  3. 3
      apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex
  4. 2
      apps/explorer_web/lib/explorer_web/notifier.ex
  5. 3
      apps/explorer_web/test/explorer_web/features/viewing_chain_test.exs
  6. 2
      apps/explorer_web/test/support/fake_adapter.ex

@ -69,7 +69,7 @@ defmodule Explorer.Chain do
Estimated count of addresses Estimated count of addresses
""" """
@spec address_estimated_count() :: non_neg_integer() @spec address_estimated_count :: non_neg_integer()
def address_estimated_count do def address_estimated_count do
%Postgrex.Result{rows: [[rows]]} = %Postgrex.Result{rows: [[rows]]} =
SQL.query!(Repo, "SELECT reltuples::BIGINT AS estimate FROM pg_class WHERE relname='addresses'") SQL.query!(Repo, "SELECT reltuples::BIGINT AS estimate FROM pg_class WHERE relname='addresses'")
@ -188,12 +188,11 @@ defmodule Explorer.Chain do
|> Repo.all() |> Repo.all()
end end
@doc """ @doc """
The average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` The average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0`
""" """
@spec average_block_time() :: non_neg_integer() @spec average_block_time :: %Timex.Duration{}
def average_block_time() do def average_block_time do
{:ok, %Postgrex.Result{rows: [[rows]]}} = {:ok, %Postgrex.Result{rows: [[rows]]}} =
SQL.query( SQL.query(
Repo, Repo,
@ -652,23 +651,6 @@ defmodule Explorer.Chain do
Import.all(options) Import.all(options)
end 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 """ @doc """
The number of `t:Explorer.Chain.InternalTransaction.t/0`. The number of `t:Explorer.Chain.InternalTransaction.t/0`.

@ -88,10 +88,10 @@ router.when('', { exactPathMatch: true }).then(({ locale }) => initRedux(reducer
const $transactionCount = $('[data-selector="transaction-count"]') const $transactionCount = $('[data-selector="transaction-count"]')
if (oldState.addressCount !== state.addressCount) { if (oldState.addressCount !== state.addressCount) {
$addressCount.empty().append(state.addressCount) $addressCount.empty().append(state.addressCount)
} }
if (oldState.averageBlockTime !== state.averageBlockTime) { if (oldState.averageBlockTime !== state.averageBlockTime) {
$averageBlockTime.empty().append(state.averageBlockTime) $averageBlockTime.empty().append(state.averageBlockTime)
} }
if (oldState.newBlock !== state.newBlock) { if (oldState.newBlock !== state.newBlock) {
$blockList.children().last().remove() $blockList.children().last().remove()

@ -1,8 +1,7 @@
defmodule ExplorerWeb.ChainController do defmodule ExplorerWeb.ChainController do
use ExplorerWeb, :controller use ExplorerWeb, :controller
alias Explorer.{PagingOptions, Repo} alias Explorer.{Chain, PagingOptions, Repo}
alias Explorer.Chain
alias Explorer.Chain.{Address, Block, Transaction} alias Explorer.Chain.{Address, Block, Transaction}
alias Explorer.ExchangeRates.Token alias Explorer.ExchangeRates.Token
alias Explorer.Market alias Explorer.Market

@ -48,7 +48,7 @@ defmodule ExplorerWeb.Notifier do
Endpoint.broadcast("blocks:new_block", "new_block", %{ Endpoint.broadcast("blocks:new_block", "new_block", %{
block: preloaded_block, block: preloaded_block,
average_block_time: Chain.average_block_time() average_block_time: Chain.average_block_time()
}) })
end end
defp broadcast_transaction(transaction) do defp broadcast_transaction(transaction) do

@ -30,6 +30,7 @@ defmodule ExplorerWeb.ViewingChainTest do
describe "statistics" do describe "statistics" do
test "average block time live updates", %{session: session} do test "average block time live updates", %{session: session} do
time = DateTime.utc_now() time = DateTime.utc_now()
for x <- 100..0 do for x <- 100..0 do
insert(:block, timestamp: Timex.shift(time, seconds: -5 * x), number: x + 500) insert(:block, timestamp: Timex.shift(time, seconds: -5 * x), number: x + 500)
end end
@ -40,7 +41,7 @@ defmodule ExplorerWeb.ViewingChainTest do
block = block =
100..0 100..0
|> Enum.map(fn(index) -> |> Enum.map(fn index ->
insert(:block, timestamp: Timex.shift(time, seconds: -10 * index), number: index + 800) insert(:block, timestamp: Timex.shift(time, seconds: -10 * index), number: index + 800)
end) end)
|> hd() |> hd()

@ -2,7 +2,7 @@ defmodule ExplorerWeb.FakeAdapter do
alias Explorer.Chain.Address alias Explorer.Chain.Address
alias Explorer.Repo alias Explorer.Repo
def address_estimated_count() do def address_estimated_count do
Repo.aggregate(Address, :count, :hash) Repo.aggregate(Address, :count, :hash)
end end
end end

Loading…
Cancel
Save