diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 0c91ef33db..4edc94887a 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.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) diff --git a/apps/explorer/lib/explorer/chain/blocks_cache.ex b/apps/explorer/lib/explorer/chain/blocks_cache.ex index 3b9174d965..778d2bc5d6 100644 --- a/apps/explorer/lib/explorer/chain/blocks_cache.ex +++ b/apps/explorer/lib/explorer/chain/blocks_cache.ex @@ -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)