Skip to content

Commit

Permalink
fix(explorer): add top hosts cache revalidation on undefined or empty
Browse files Browse the repository at this point in the history
  • Loading branch information
telestrial committed Feb 24, 2025
1 parent e215d4e commit 4456825
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-emus-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'explorer': minor
---

Improved top host list redundancy.
8 changes: 5 additions & 3 deletions apps/explorer/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 }
)

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions apps/explorer/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 4456825

Please sign in to comment.