diff --git a/apps/web/components/memories-grid.tsx b/apps/web/components/memories-grid.tsx index 9974f740..0959cff9 100644 --- a/apps/web/components/memories-grid.tsx +++ b/apps/web/components/memories-grid.tsx @@ -75,11 +75,18 @@ type OgData = { const ogCache = new Map() const ogInflight = new Map>() +const ogFailures = new Map() +const OG_FAILURE_TTL = 30_000 function fetchOgData(url: string): Promise { const cached = ogCache.get(url) if (cached) return Promise.resolve(cached) + const failedAt = ogFailures.get(url) + if (failedAt && Date.now() - failedAt < OG_FAILURE_TTL) { + return Promise.resolve(null) + } + const inflight = ogInflight.get(url) if (inflight) return inflight @@ -92,10 +99,12 @@ function fetchOgData(url: string): Promise { const result: OgData = { title: data?.title, image: data?.image } ogCache.set(url, result) ogInflight.delete(url) + ogFailures.delete(url) return result }) .catch(() => { ogInflight.delete(url) + ogFailures.set(url, Date.now()) return null })