From 5d59797d5de96381e1b76e0f5ff425f95ceac967 Mon Sep 17 00:00:00 2001 From: Jure <44338+hoornet@users.noreply.github.com> Date: Mon, 13 Apr 2026 21:34:40 +0200 Subject: [PATCH] Add thread load timing diagnostics (Ctrl+Shift+D to view) --- src/components/thread/ThreadView.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/thread/ThreadView.tsx b/src/components/thread/ThreadView.tsx index 49e7748..711ee3c 100644 --- a/src/components/thread/ThreadView.tsx +++ b/src/components/thread/ThreadView.tsx @@ -8,6 +8,7 @@ import { fetchNoteById, fetchThreadEvents, fetchAncestors, publishReply, getNDK, import { buildThreadTree, getRootEventId } from "../../lib/threadTree"; import type { ThreadNode } from "../../lib/threadTree"; import { debug } from "../../lib/debug"; +import { logDiag } from "../../lib/feedDiagnostics"; import { AncestorChain } from "./AncestorChain"; import { ThreadNodeComponent } from "./ThreadNode"; import { NoteCard } from "../feed/NoteCard"; @@ -65,12 +66,15 @@ export function ThreadView() { let root: NDKEvent = focusedEvent; let fetchedAncestors: NDKEvent[] = []; + logDiag({ ts: new Date().toISOString(), action: "thread_load_start", details: `rootId=${rootId ?? "none"} focusedId=${focusedEvent.id}` }); + if (rootId && rootId !== focusedEvent.id) { - // Fetch root and ancestors in parallel with thread replies + const t0 = Date.now(); const [fetched, ancestorResult] = await Promise.all([ fetchNoteById(rootId), fetchAncestors(focusedEvent), ]); + logDiag({ ts: new Date().toISOString(), action: "thread_root_ancestors", durationMs: Date.now() - t0, details: `root=${fetched ? "ok" : "missing"} ancestors=${ancestorResult.length}` }); if (fetched) { root = fetched; fetchedAncestors = ancestorResult.filter((a) => a.id !== root.id); @@ -83,7 +87,10 @@ export function ThreadView() { if (cancelled) return; setRootEvent(root); + logDiag({ ts: new Date().toISOString(), action: "thread_replies_start", details: `rootId=${root.id}` }); + const t1 = Date.now(); const events = await fetchThreadEvents(root.id); + logDiag({ ts: new Date().toISOString(), action: "thread_replies_done", durationMs: Date.now() - t1, details: `count=${events.length}` }); if (cancelled) return; // Build event list: root + thread replies + focused event + ancestors