Fix profile fetch architecture: batch kind-0 queries, restore NDK pooling

This commit is contained in:
Jure
2026-04-13 21:06:08 +02:00
parent d8217bda49
commit 95785dcb07
5 changed files with 30 additions and 14 deletions
+5 -2
View File
@@ -4,7 +4,7 @@ import { useUserStore } from "../../stores/user";
import { useMuteStore } from "../../stores/mute";
import { useUIStore } from "../../stores/ui";
import { useWoTStore } from "../../stores/wot";
import { fetchFollowFeed, getNDK, ensureConnected } from "../../lib/nostr";
import { fetchFollowFeed, getNDK, ensureConnected, batchFetchProfileAges } from "../../lib/nostr";
import { diagWrapFetch, logDiag } from "../../lib/feedDiagnostics";
import { detectScript, getEventLanguageTag, FILTER_SCRIPTS } from "../../lib/language";
import { NoteCard } from "./NoteCard";
@@ -63,7 +63,10 @@ export function Feed() {
useEffect(() => {
// Show cached notes immediately, then fetch fresh ones once connected
loadCachedFeed();
connect().then(() => loadFeed());
connect().then(() => loadFeed().then(() => {
const pubkeys = [...new Set(useFeedStore.getState().notes.map((e) => e.pubkey))];
batchFetchProfileAges(pubkeys);
}));
}, []);
+2 -2
View File
@@ -6,7 +6,7 @@ import { useUserStore } from "../../stores/user";
import { useMuteStore } from "../../stores/mute";
import { useUIStore } from "../../stores/ui";
import { timeAgo, shortenPubkey } from "../../lib/utils";
import { getNDK, fetchNoteById, ensureConnected } from "../../lib/nostr";
import { getNDK, fetchNoteById, ensureConnected, getProfileAge } from "../../lib/nostr";
import { getParentEventId } from "../../lib/threadTree";
import { NoteContent } from "./NoteContent";
import { NoteActions, LoggedOutStats } from "./NoteActions";
@@ -34,7 +34,7 @@ export const NoteCard = memo(function NoteCard({ event, focused, onReplyInThread
const nip05 = typeof profile?.nip05 === "string" ? profile.nip05 : null;
const verified = useNip05Verified(event.pubkey, nip05);
const time = event.created_at ? timeAgo(event.created_at) : "";
const profileCreatedAt = typeof profile?._createdAt === "number" ? profile._createdAt : null;
const profileCreatedAt = getProfileAge(event.pubkey);
const isNewAccount = profileCreatedAt !== null && (Date.now() / 1000 - profileCreatedAt) < 60 * 24 * 3600;
const loggedIn = useUserStore((s) => s.loggedIn);
+2 -1
View File
@@ -4,7 +4,7 @@ import { useAutoResize } from "../../hooks/useAutoResize";
import { useUIStore } from "../../stores/ui";
import { useUserStore } from "../../stores/user";
import { useMuteStore } from "../../stores/mute";
import { fetchNoteById, fetchThreadEvents, fetchAncestors, publishReply, getNDK, ensureConnected } from "../../lib/nostr";
import { fetchNoteById, fetchThreadEvents, fetchAncestors, publishReply, getNDK, ensureConnected, batchFetchProfileAges } from "../../lib/nostr";
import { buildThreadTree, getRootEventId } from "../../lib/threadTree";
import type { ThreadNode } from "../../lib/threadTree";
import { debug } from "../../lib/debug";
@@ -99,6 +99,7 @@ export function ThreadView() {
const built = buildThreadTree(root.id, allEvents);
setTree(built);
batchFetchProfileAges([...new Set(allEvents.map((e) => e.pubkey))]);
} catch (err) {
debug.error("Failed to load thread:", err);
if (!cancelled) setLoadError(`Failed to load: ${err}`);