Merge pull request #2822 from poanetwork/vb-estimated-address-count

Estimated address count on the main page
pull/2841/head
Victor Baranov 5 years ago committed by GitHub
commit b196c0b21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/block_scout_web/assets/js/pages/token_counters.js
  3. 2
      apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex
  4. 3
      apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex
  5. 2
      apps/block_scout_web/lib/block_scout_web/notifier.ex
  6. 18
      apps/explorer/lib/explorer/chain.ex
  7. 4
      apps/explorer/test/explorer/chain_test.exs

@ -4,6 +4,7 @@
- [#2787](https://github.com/poanetwork/blockscout/pull/2787) - async fetching of address counters - [#2787](https://github.com/poanetwork/blockscout/pull/2787) - async fetching of address counters
- [#2791](https://github.com/poanetwork/blockscout/pull/2791) - add ipc client - [#2791](https://github.com/poanetwork/blockscout/pull/2791) - add ipc client
- [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify - [#2449](https://github.com/poanetwork/blockscout/pull/2449) - add ability to send notification events through postgres notify
- [#2822](https://github.com/poanetwork/blockscout/pull/2822) - Estimated address count on the main page, if cache is empty
### Fixes ### Fixes
- [#2830](https://github.com/poanetwork/blockscout/pull/2830) - Fix wrong color of contract icon on xDai chain - [#2830](https://github.com/poanetwork/blockscout/pull/2830) - Fix wrong color of contract icon on xDai chain

@ -66,7 +66,7 @@ const elements = {
function loadCounters (store) { function loadCounters (store) {
const $element = $('[data-async-counters]') const $element = $('[data-async-counters]')
const path = $element.data().asyncCounters const path = $element.data() && $element.data().asyncCounters
function fetchCounters () { function fetchCounters () {
store.dispatch({type: 'START_REQUEST'}) store.dispatch({type: 'START_REQUEST'})
$.getJSON(path) $.getJSON(path)

@ -59,7 +59,7 @@ defmodule BlockScoutWeb.AddressController do
def index(conn, _params) do def index(conn, _params) do
render(conn, "index.html", render(conn, "index.html",
current_path: current_path(conn), current_path: current_path(conn),
address_count: Chain.count_addresses_from_cache() address_count: Chain.address_estimated_count()
) )
end end

@ -13,6 +13,7 @@ defmodule BlockScoutWeb.ChainController do
def show(conn, _params) do def show(conn, _params) do
transaction_estimated_count = Chain.transaction_estimated_count() transaction_estimated_count = Chain.transaction_estimated_count()
block_count = Chain.block_estimated_count() block_count = Chain.block_estimated_count()
address_count = Chain.address_estimated_count()
market_cap_calculation = market_cap_calculation =
case Application.get_env(:explorer, :supply) do case Application.get_env(:explorer, :supply) do
@ -28,7 +29,7 @@ defmodule BlockScoutWeb.ChainController do
render( render(
conn, conn,
"show.html", "show.html",
address_count: Chain.count_addresses_from_cache(), address_count: address_count,
average_block_time: AverageBlockTime.average_block_time(), average_block_time: AverageBlockTime.average_block_time(),
exchange_rate: exchange_rate, exchange_rate: exchange_rate,
chart_data_path: market_history_chart_path(conn, :show), chart_data_path: market_history_chart_path(conn, :show),

@ -14,7 +14,7 @@ defmodule BlockScoutWeb.Notifier do
alias Phoenix.View alias Phoenix.View
def handle_event({:chain_event, :addresses, type, addresses}) when type in [:realtime, :on_demand] do def handle_event({:chain_event, :addresses, type, addresses}) when type in [:realtime, :on_demand] do
Endpoint.broadcast("addresses:new_address", "count", %{count: Chain.count_addresses_from_cache()}) Endpoint.broadcast("addresses:new_address", "count", %{count: Chain.address_estimated_count()})
addresses addresses
|> Stream.reject(fn %Address{fetched_coin_balance: fetched_coin_balance} -> is_nil(fetched_coin_balance) end) |> Stream.reject(fn %Address{fetched_coin_balance: fetched_coin_balance} -> is_nil(fetched_coin_balance) end)

@ -122,11 +122,21 @@ defmodule Explorer.Chain do
end end
@doc """ @doc """
Gets from the cache the count of all `t:Explorer.Chain.Address.t/0`'s Estimated count of `t:Explorer.Chain.Address.t/0`.
Estimated count of addresses.
""" """
@spec count_addresses_from_cache :: non_neg_integer() @spec address_estimated_count() :: non_neg_integer()
def count_addresses_from_cache do def address_estimated_count do
AddressesCounter.fetch() cached_value = AddressesCounter.fetch()
if is_nil(cached_value) do
%Postgrex.Result{rows: [[count]]} = Repo.query!("SELECT reltuples FROM pg_class WHERE relname = 'addresses';")
count
else
cached_value
end
end end
@doc """ @doc """

@ -51,7 +51,7 @@ defmodule Explorer.ChainTest do
end end
end end
describe "count_addresses_from_cache/0" do describe "address_estimated_count/0" do
test "returns the number of all addresses" do test "returns the number of all addresses" do
insert(:address, fetched_coin_balance: 0) insert(:address, fetched_coin_balance: 0)
insert(:address, fetched_coin_balance: 1) insert(:address, fetched_coin_balance: 1)
@ -60,7 +60,7 @@ defmodule Explorer.ChainTest do
start_supervised!(AddressesCounter) start_supervised!(AddressesCounter)
AddressesCounter.consolidate() AddressesCounter.consolidate()
addresses_with_balance = Chain.count_addresses_from_cache() addresses_with_balance = Chain.address_estimated_count()
assert is_integer(addresses_with_balance) assert is_integer(addresses_with_balance)
assert addresses_with_balance == 3 assert addresses_with_balance == 3

Loading…
Cancel
Save