diff --git a/apps/explorer/lib/explorer/chain/statistics.ex b/apps/explorer/lib/explorer/chain/statistics.ex index cebe2975fe..0d058525be 100644 --- a/apps/explorer/lib/explorer/chain/statistics.ex +++ b/apps/explorer/lib/explorer/chain/statistics.ex @@ -19,24 +19,8 @@ defmodule Explorer.Chain.Statistics do ) t """ - @lag_query """ - SELECT coalesce(avg(lag), interval '0 seconds') - FROM ( - SELECT inserted_at - timestamp AS lag - FROM blocks - WHERE blocks.inserted_at > NOW() - interval '1 hour' - AND blocks.timestamp > NOW() - interval '1 hour' - ) t - """ - - @block_velocity_query """ - SELECT count(blocks.hash) - FROM blocks - WHERE blocks.inserted_at > NOW() - interval '1 minute' - """ - @transaction_velocity_query """ - SELECT count(transactions.hash) + SELECT count(transactions.inserted_at) FROM transactions WHERE transactions.inserted_at > NOW() - interval '1 minute' """ @@ -53,9 +37,7 @@ defmodule Explorer.Chain.Statistics do @typedoc """ * `average_time` - the average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` - * `block_velocity` - the number of `t:Explorer.Chain.Block.t/0` mined/validated in the last minute * `blocks` - the last <= 5 `t:Explorer.Chain.Block.t/0` - * `lag` - the average time over the last hour between when the block was mined/validated (`t:Explorer.Chain.Block.t/0` `timestamp`) and when it was inserted into the databasse (`t:Explorer.Chain.Block.t/0` `inserted_at`) * `number` - the latest `t:Explorer.Chain.Block.t/0` `number` @@ -66,9 +48,7 @@ defmodule Explorer.Chain.Statistics do """ @type t :: %__MODULE__{ average_time: Duration.t(), - block_velocity: blocks_per_minute(), blocks: [Block.t()], - lag: Duration.t(), number: Block.block_number(), timestamp: :calendar.datetime(), transaction_velocity: transactions_per_minute(), @@ -76,9 +56,7 @@ defmodule Explorer.Chain.Statistics do } defstruct average_time: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, - block_velocity: 0, blocks: [], - lag: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, number: -1, timestamp: nil, transaction_velocity: 0, @@ -105,9 +83,7 @@ defmodule Explorer.Chain.Statistics do %__MODULE__{ average_time: query_duration(@average_time_query), - block_velocity: query_value(@block_velocity_query), blocks: Repo.all(blocks), - lag: query_duration(@lag_query), transaction_velocity: query_value(@transaction_velocity_query), transactions: transactions } diff --git a/apps/explorer/test/explorer/chain/statistics_test.exs b/apps/explorer/test/explorer/chain/statistics_test.exs index 78a5f90026..ba8a45a239 100644 --- a/apps/explorer/test/explorer/chain/statistics_test.exs +++ b/apps/explorer/test/explorer/chain/statistics_test.exs @@ -45,24 +45,6 @@ defmodule Explorer.Chain.StatisticsTest do } = Statistics.fetch() end - test "returns the lag between validation and insertion time" do - validation_time = DateTime.utc_now() - inserted_at = validation_time |> Timex.shift(seconds: 5) - insert(:block, timestamp: validation_time, inserted_at: inserted_at) - - assert %Statistics{lag: %Duration{seconds: 5, megaseconds: 0, microseconds: 0}} = Statistics.fetch() - end - - test "returns the number of blocks inserted in the last minute" do - old_inserted_at = Timex.shift(DateTime.utc_now(), days: -1) - insert(:block, inserted_at: old_inserted_at) - insert(:block) - - statistics = Statistics.fetch() - - assert statistics.block_velocity == 1 - end - test "returns the number of transactions inserted in the last minute" do old_inserted_at = Timex.shift(DateTime.utc_now(), days: -1) insert(:transaction, inserted_at: old_inserted_at)