Instant thread display, faster fetches, trending always shows notes

Threads now render the focused note immediately instead of showing a
loading skeleton. Root + ancestors fetch in parallel, timeouts cut
from 10s to 5s per round-trip, ancestor lookups from 5s to 2s.

Trending feed adds a base recency score so notes always appear even
when engagement data times out from relays.
This commit is contained in:
Jure
2026-03-29 17:50:10 +02:00
parent 8e685f2d4b
commit 2bb1341eed
4 changed files with 27 additions and 23 deletions

View File

@@ -14,7 +14,7 @@ export function withTimeout<T>(promise: Promise<T>, ms: number, fallback: T): Pr
}
export const FEED_TIMEOUT = 8000; // 8s for feed fetches
export const THREAD_TIMEOUT = 10000; // 10s per thread round-trip
export const THREAD_TIMEOUT = 5000; // 5s per thread round-trip
export const SINGLE_TIMEOUT = 5000; // 5s for single event lookups
const EMPTY_SET = new Set<NDKEvent>();

View File

@@ -148,6 +148,8 @@ export async function fetchThreadEvents(rootId: string): Promise<NDKEvent[]> {
return Array.from(allEvents.values());
}
const ANCESTOR_TIMEOUT = 2000; // 2s per parent — fail fast
export async function fetchAncestors(event: NDKEvent, maxDepth = 5): Promise<NDKEvent[]> {
const ancestors: NDKEvent[] = [];
let current = event;
@@ -162,7 +164,10 @@ export async function fetchAncestors(event: NDKEvent, maxDepth = 5): Promise<NDK
eTags[eTags.length - 1][1];
if (!parentId) break;
const parent = await fetchNoteById(parentId);
const instance = getNDK();
const filter: NDKFilter = { ids: [parentId], limit: 1 };
const events = await fetchWithTimeout(instance, filter, ANCESTOR_TIMEOUT);
const parent = Array.from(events)[0] ?? null;
if (!parent) break;
ancestors.unshift(parent);
current = parent;