optimize blocks fetching from cache

pull/2075/head
Ayrat Badykov 6 years ago
parent b40f2e8c5a
commit 85439d8740
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 4
      apps/explorer/lib/explorer/chain.ex
  2. 5
      apps/explorer/lib/explorer/chain/blocks_cache.ex

@ -1155,9 +1155,7 @@ defmodule Explorer.Chain do
if block_type == "Block" && !paging_options.key do
if BlocksCache.enough_elements?(paging_options.page_size) do
cached_blocks = BlocksCache.blocks()
Enum.slice(cached_blocks, 0, paging_options.page_size)
BlocksCache.blocks(paging_options.page_size)
else
elements = fetch_blocks(block_type, paging_options, necessity_by_association)

@ -56,12 +56,15 @@ defmodule Explorer.Chain.BlocksCache do
end)
end
def blocks do
def blocks(number \\ nil) do
numbers = block_numbers()
number = if is_nil(number), do: Enum.count(numbers), else: number
numbers
|> Enum.sort()
|> Enum.reverse()
|> Enum.slice(0, number)
|> Enum.map(fn number ->
ConCache.get(@cache_name, number)
end)

Loading…
Cancel
Save