fix: Fix sitemap timeout; optimize OrderedCache preloads (#11131)

* fix: Fix sitemap timeout; optimize OrderedCache preloads

* Process review comments
ap-http-client-test
nikitosing 2 weeks ago committed by GitHub
parent 001ab94af4
commit 1223faae6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/robots/sitemap.xml.eex
  2. 2
      apps/block_scout_web/lib/block_scout_web/views/robots_view.ex
  3. 2
      apps/explorer/lib/explorer/chain.ex
  4. 9
      apps/explorer/lib/explorer/chain/address.ex
  5. 3
      apps/explorer/lib/explorer/chain/ordered_cache.ex
  6. 9
      apps/explorer/lib/explorer/chain/token.ex

@ -2,7 +2,7 @@
<% host = APIDocsView.blockscout_url(true) %>
<% date = to_string(Date.utc_today()) %>
<% non_parameterized_urls = ["/", "/txs", "/blocks", "/accounts", "/verified-contracts", "/tokens", "/apps", "/stats", "/api-docs", "/graphiql", "/search-results", "/withdrawals", "/l2-deposits", "/l2-output-roots", "/l2-txn-batches", "/l2-withdrawals"] %>
<% params = [paging_options: %PagingOptions{page_size: limit()}] %>
<% params = [paging_options: %PagingOptions{page_size: limit()}, necessity_by_association: %{}] %>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<%= for url <- non_parameterized_urls do %>
<url>

@ -5,6 +5,6 @@ defmodule BlockScoutWeb.RobotsView do
alias Explorer.{Chain, PagingOptions}
alias Explorer.Chain.{Address, Token}
@limit 200
@limit 50
defp limit, do: @limit
end

@ -795,7 +795,7 @@ defmodule Explorer.Chain do
from(contract in SmartContract,
inner_join: address in Address,
on: contract.address_hash == address.hash,
order_by: [desc: address.transactions_count],
order_by: [desc: address.fetched_coin_balance],
limit: ^limit,
select: contract.address_hash
)

@ -543,6 +543,13 @@ defmodule Explorer.Chain.Address do
defp fetch_top_addresses(options) do
paging_options = Keyword.get(options, :paging_options, @default_paging_options)
necessity_by_association =
Keyword.get(options, :necessity_by_association, %{
:names => :optional,
:smart_contract => :optional,
proxy_implementations_association() => :optional
})
case paging_options do
%PagingOptions{key: {0, _hash}} ->
[]
@ -552,11 +559,11 @@ defmodule Explorer.Chain.Address do
from(a in Address,
where: a.fetched_coin_balance > ^0,
order_by: [desc: a.fetched_coin_balance, asc: a.hash],
preload: [:names, :smart_contract, ^proxy_implementations_association()],
select: {a, a.transactions_count}
)
base_query
|> Chain.join_associations(necessity_by_association)
|> ExplorerHelper.maybe_hide_scam_addresses(:hash)
|> page_addresses(paging_options)
|> limit(^paging_options.page_size)

@ -247,9 +247,10 @@ defmodule Explorer.Chain.OrderedCache do
ConCache.update(cache_name(), ids_list_key(), fn ids ->
updated_list =
elements
|> Enum.sort_by(&element_to_id(&1), &prevails?(&1, &2))
|> Enum.take(max_size())
|> do_preloads()
|> Enum.map(&{element_to_id(&1), &1})
|> Enum.sort(&prevails?(&1, &2))
|> merge_and_update(ids || [], max_size())
# ids_list is set to never expire

@ -201,16 +201,21 @@ defmodule Explorer.Chain.Token do
Chain.paging_options()
| {:sorting, SortingHelper.sorting_params()}
| {:token_type, [String.t()]}
| {:necessity_by_association, map()}
]) :: [Token.t()]
def list_top(filter, options \\ []) do
paging_options = Keyword.get(options, :paging_options, Chain.default_paging_options())
token_type = Keyword.get(options, :token_type, nil)
sorting = Keyword.get(options, :sorting, [])
query = from(t in Token, preload: [:contract_address])
necessity_by_association =
Keyword.get(options, :necessity_by_association, %{
:contract_address => :optional
})
sorted_paginated_query =
query
Token
|> Chain.join_associations(necessity_by_association)
|> ExplorerHelper.maybe_hide_scam_addresses(:contract_address_hash)
|> apply_filter(token_type)
|> SortingHelper.apply_sorting(sorting, @default_sorting)

Loading…
Cancel
Save