diff --git a/.changeset/loud-emus-sin.md b/.changeset/loud-emus-sin.md new file mode 100644 index 000000000..1bff965f8 --- /dev/null +++ b/.changeset/loud-emus-sin.md @@ -0,0 +1,5 @@ +--- +'explorer': minor +--- + +Improved top host list redundancy. diff --git a/apps/explorer/app/page.tsx b/apps/explorer/app/page.tsx index 330d28e0a..69854ed1f 100644 --- a/apps/explorer/app/page.tsx +++ b/apps/explorer/app/page.tsx @@ -1,12 +1,12 @@ import { Metadata } from 'next' -import { appLink, network } from '../config' +import { appLink, network, topHostsCacheTag } from '../config' import { Home } from '../components/Home' import { buildMetadata } from '../lib/utils' import { getLatestBlocks } from '../lib/blocks' import { to } from '@siafoundation/request' import { explored } from '../config/explored' import { rankHosts } from '../lib/hosts' -import { unstable_cache } from 'next/cache' +import { revalidateTag, unstable_cache } from 'next/cache' export function generateMetadata(): Metadata { const title = 'siascan' @@ -37,7 +37,7 @@ const getCachedTopHosts = unstable_cache( .slice(0, 5) // Select the top 5. .map((result) => result.host) // Strip score key. }, - ['top-hosts'], + [topHostsCacheTag], { revalidate: 86400 } ) @@ -46,6 +46,8 @@ export default async function HomePage() { await Promise.all([to(explored.hostMetrics()), to(explored.blockMetrics())]) const selectedTopHosts = await getCachedTopHosts() + if (!selectedTopHosts || selectedTopHosts.length === 0) + revalidateTag(topHostsCacheTag) const [latestBlocks, latestBlocksError] = await getLatestBlocks() const latestHeight = latestBlocks ? latestBlocks[0].height : 0 diff --git a/apps/explorer/config/index.ts b/apps/explorer/config/index.ts index f24a0501b..0ba27db18 100644 --- a/apps/explorer/config/index.ts +++ b/apps/explorer/config/index.ts @@ -6,6 +6,7 @@ export const siteName = 'siascan.com' export const appName = 'siascan' export const appLink = webLinks.explore.mainnet export const isMainnet = true +export const topHostsCacheTag = 'top-hosts' // APIs export const faucetApi = 'https://api.siascan.com/zen/faucet'