diff --git a/src/config.ts b/src/config.ts index cdd88705..5bc5d865 100644 --- a/src/config.ts +++ b/src/config.ts @@ -334,7 +334,7 @@ class Conf { /** Link preview cache settings. */ get linkPreview(): { max: number; ttl: number } { return { - max: Number(Deno.env.get('DITTO_CACHE_LINK_PREVIEW_MAX') || 1000), + max: Number(Deno.env.get('DITTO_CACHE_LINK_PREVIEW_MAX') || 3000), ttl: Number(Deno.env.get('DITTO_CACHE_LINK_PREVIEW_TTL') || 12 * 60 * 60 * 1000), }; }, diff --git a/src/pipeline.ts b/src/pipeline.ts index 7540bc82..31912530 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -19,9 +19,11 @@ import { getAmount } from '@/utils/bolt11.ts'; import { faviconCache } from '@/utils/favicon.ts'; import { errorJson } from '@/utils/log.ts'; import { nip05Cache } from '@/utils/nip05.ts'; +import { parseNoteContent, stripimeta } from '@/utils/note.ts'; import { purifyEvent } from '@/utils/purify.ts'; import { updateStats } from '@/utils/stats.ts'; import { getTagSet } from '@/utils/tags.ts'; +import { unfurlCardCached } from '@/utils/unfurl.ts'; import { renderWebPushNotification } from '@/views/mastodon/push.ts'; import { policyWorker } from '@/workers/policy.ts'; import { verifyEventWorker } from '@/workers/verify.ts'; @@ -122,6 +124,7 @@ async function handleEvent(event: DittoEvent, opts: PipelineOpts): Promise Promise.allSettled([ handleZaps(kysely, event), updateAuthorData(event, opts.signal), + prewarmLinkPreview(event, opts.signal), generateSetEvents(event), ]) .then(() => @@ -268,6 +271,13 @@ async function updateAuthorData(event: NostrEvent, signal: AbortSignal): Promise } } +async function prewarmLinkPreview(event: NostrEvent, signal: AbortSignal): Promise { + const { firstUrl } = parseNoteContent(stripimeta(event.content, event.tags), []); + if (firstUrl) { + await unfurlCardCached(firstUrl, signal); + } +} + /** Determine if the event is being received in a timely manner. */ function isFresh(event: NostrEvent): boolean { return eventAge(event) < Time.minutes(1); diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index 0c0eb9f2..00f7dd55 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -46,7 +46,7 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise< const [card, relatedEvents] = await Promise .all([ - firstUrl ? unfurlCardCached(firstUrl) : null, + firstUrl ? unfurlCardCached(firstUrl, AbortSignal.timeout(500)) : null, viewerPubkey ? await store.query([ { kinds: [6], '#e': [event.id], authors: [viewerPubkey], limit: 1 },