From dd565ccb167cf7cf6d4aeedfda61ae9eb690507f Mon Sep 17 00:00:00 2001 From: Jure <44338+hoornet@users.noreply.github.com> Date: Sun, 29 Mar 2026 18:23:02 +0200 Subject: [PATCH] Increase mention fetch timeout and retry on empty Tag-based #p queries are slower on some relays. Increase timeout from 8s to 12s for fetchMentions. Also retry once after 3s if the initial notification fetch returns empty (helps on cold start when relays need time to connect). --- src/lib/nostr/social.ts | 3 ++- src/stores/notifications.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/nostr/social.ts b/src/lib/nostr/social.ts index 11f12f6..589bb5a 100644 --- a/src/lib/nostr/social.ts +++ b/src/lib/nostr/social.ts @@ -74,10 +74,11 @@ export async function fetchFollowSuggestions(myFollows: string[]): Promise<{ pub export async function fetchMentions(pubkey: string, since: number, limit = 50): Promise { const instance = getNDK(); + // Use a longer timeout for #p queries — some relays are slow to index tag lookups const events = await fetchWithTimeout( instance, { kinds: [NDKKind.Text], "#p": [pubkey], since, limit }, - FEED_TIMEOUT, + 12000, ); return Array.from(events).sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0)); } diff --git a/src/stores/notifications.ts b/src/stores/notifications.ts index 2f9b3a4..1fca5b2 100644 --- a/src/stores/notifications.ts +++ b/src/stores/notifications.ts @@ -100,10 +100,18 @@ export const useNotificationsStore = create((set, get) => ({ set({ loading: true }); try { const since = Math.floor(Date.now() / 1000) - 7 * 86400; - const events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS); - const others = events.filter((e) => e.pubkey !== pubkey); + let events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS); + let others = events.filter((e) => e.pubkey !== pubkey); debug.log("notif:fetch", events.length, "raw →", others.length, "others"); + // Retry once if empty — relays may need more time for #p tag queries + if (others.length === 0) { + await new Promise((r) => setTimeout(r, 3000)); + events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS); + others = events.filter((e) => e.pubkey !== pubkey); + debug.log("notif:fetch retry →", others.length, "others"); + } + // Don't overwrite existing notifications with empty results (relay timeout/disconnect) const { readIds, notifications: existing } = get(); if (others.length === 0 && existing.length > 0) {