Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get estimated count of blocks when cache is empty #2002

Merged
merged 3 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method
- [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default
- [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct
- [#2002](https://github.com/poanetwork/blockscout/pull/2002) - Get estimated count of blocks when cache is empty

### Fixes

Expand Down
19 changes: 3 additions & 16 deletions apps/explorer/lib/explorer/chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,6 @@ defmodule Explorer.Chain do
Repo.aggregate(Block, :count, :hash)
end

@doc """
The number of consensus blocks.

iex> insert(:block, consensus: true)
iex> insert(:block, consensus: false)
iex> Explorer.Chain.block_consensus_count()
1

"""
def block_consensus_count do
Block
|> where(consensus: true)
|> Repo.aggregate(:count, :hash)
end

@doc """
Reward for mining a block.

Expand Down Expand Up @@ -1997,7 +1982,9 @@ defmodule Explorer.Chain do
cached_value = BlockCountCache.count()

if is_nil(cached_value) do
block_consensus_count()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saneery should we remove or mark with the comment, that block_consensus_count function is not used anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think, we can just remove this function

%Postgrex.Result{rows: [[count]]} = Repo.query!("SELECT reltuples FROM pg_class WHERE relname = 'blocks';")

trunc(count * 0.90)
else
cached_value
end
Expand Down