chore(debug): add [archive] debug logs in archiveController, Me, and ContentPanel to trace archive filter behavior

This commit is contained in:
Gigi
2025-10-20 10:48:44 +02:00
parent 8337622a22
commit c9fef5804b
3 changed files with 28 additions and 1 deletions

View File

@@ -573,6 +573,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
try { try {
const naddr = nip19.naddrEncode({ kind: 30023, pubkey: currentArticle.pubkey, identifier: dTag }) const naddr = nip19.naddrEncode({ kind: 30023, pubkey: currentArticle.pubkey, identifier: dTag })
hasRead = hasRead || archiveController.isMarked(naddr) hasRead = hasRead || archiveController.isMarked(naddr)
console.log('[archive][content] check article', { naddr: naddr.slice(0, 24) + '...', hasRead })
} catch {} } catch {}
} }
} else { } else {
@@ -582,7 +583,9 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
relayPool relayPool
) )
// Also check archiveController // Also check archiveController
hasRead = hasRead || archiveController.isMarked(selectedUrl) const ctrl = archiveController.isMarked(selectedUrl)
hasRead = hasRead || ctrl
console.log('[archive][content] check url', { url: selectedUrl, hasRead, ctrl })
} }
setIsMarkedAsRead(hasRead) setIsMarkedAsRead(hasRead)
} catch (error) { } catch (error) {
@@ -628,6 +631,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore private update for instant UI; controller will confirm via stream // @ts-ignore private update for instant UI; controller will confirm via stream
archiveController['markedIds'].add(naddr) archiveController['markedIds'].add(naddr)
console.log('[archive][content] optimistic mark article', naddr.slice(0, 24) + '...')
} }
} catch {} } catch {}
} else if (selectedUrl) { } else if (selectedUrl) {
@@ -639,6 +643,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore private update for instant UI; controller will confirm via stream // @ts-ignore private update for instant UI; controller will confirm via stream
archiveController['markedIds'].add(selectedUrl) archiveController['markedIds'].add(selectedUrl)
console.log('[archive][content] optimistic mark url', selectedUrl)
} }
} catch (error) { } catch (error) {
console.error('Failed to mark as read:', error) console.error('Failed to mark as read:', error)

View File

@@ -632,6 +632,19 @@ const Me: React.FC<MeProps> = ({
readingProgressFilter, readingProgressFilter,
highlights highlights
) )
// Debug logs for archive filter issues
if (readingProgressFilter === 'archive') {
console.log('[archive][me] counts', {
reads: reads.length,
readsWithProgress: readsWithProgress.length,
filteredReads: filteredReads.length,
links: links.length,
linksWithProgress: linksWithProgress.length,
filteredLinks: filteredLinks.length,
markedIds: archiveController.getMarkedIds().length
})
}
const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> = const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> =
groupingMode === 'flat' groupingMode === 'flat'
? [{ key: 'all', title: `All Bookmarks (${filteredBookmarks.length})`, items: filteredBookmarks }] ? [{ key: 'all', title: `All Bookmarks (${filteredBookmarks.length})`, items: filteredBookmarks }]

View File

@@ -58,11 +58,13 @@ class ArchiveController {
const startGen = this.generation const startGen = this.generation
if (!force && this.isLoadedFor(pubkey)) { if (!force && this.isLoadedFor(pubkey)) {
console.log('[archive] start() skipped - already loaded for pubkey')
return return
} }
// Mark as loaded immediately (fetch runs non-blocking) // Mark as loaded immediately (fetch runs non-blocking)
this.lastLoadedPubkey = pubkey this.lastLoadedPubkey = pubkey
console.log('[archive] start() begin for pubkey:', pubkey.slice(0, 12), '...')
const seenIds = new Set<string>() const seenIds = new Set<string>()
@@ -73,6 +75,7 @@ class ArchiveController {
if (!rTag) return if (!rTag) return
this.markedIds.add(rTag) this.markedIds.add(rTag)
this.emit() this.emit()
console.log('[archive] mark url:', rTag)
} }
const pendingEventIds = new Set<string>() const pendingEventIds = new Set<string>()
@@ -81,6 +84,7 @@ class ArchiveController {
const eTag = evt.tags.find(t => t[0] === 'e')?.[1] const eTag = evt.tags.find(t => t[0] === 'e')?.[1]
if (!eTag) return if (!eTag) return
pendingEventIds.add(eTag) pendingEventIds.add(eTag)
console.log('[archive] pending event id:', eTag)
} }
try { try {
@@ -95,25 +99,30 @@ class ArchiveController {
// Include EOSE events // Include EOSE events
kind17.forEach(handleUrlReaction) kind17.forEach(handleUrlReaction)
kind7.forEach(handleEventReaction) kind7.forEach(handleEventReaction)
console.log('[archive] EOSE sizes kind17:', kind17.length, 'kind7:', kind7.length, 'pendingEventIds:', pendingEventIds.size)
if (pendingEventIds.size > 0) { if (pendingEventIds.size > 0) {
// Fetch referenced articles (kind:30023) and map event IDs to naddr // Fetch referenced articles (kind:30023) and map event IDs to naddr
const ids = Array.from(pendingEventIds) const ids = Array.from(pendingEventIds)
const articleEvents = await queryEvents(relayPool, { kinds: [KINDS.BlogPost], ids }, { relayUrls: RELAYS }) const articleEvents = await queryEvents(relayPool, { kinds: [KINDS.BlogPost], ids }, { relayUrls: RELAYS })
console.log('[archive] fetched articles for mapping:', articleEvents.length)
for (const article of articleEvents) { for (const article of articleEvents) {
const dTag = article.tags.find(t => t[0] === 'd')?.[1] const dTag = article.tags.find(t => t[0] === 'd')?.[1]
if (!dTag) continue if (!dTag) continue
try { try {
const naddr = nip19.naddrEncode({ kind: KINDS.BlogPost, pubkey: article.pubkey, identifier: dTag }) const naddr = nip19.naddrEncode({ kind: KINDS.BlogPost, pubkey: article.pubkey, identifier: dTag })
this.markedIds.add(naddr) this.markedIds.add(naddr)
console.log('[archive] mark naddr:', naddr.slice(0, 24), '...')
} catch { } catch {
// skip invalid // skip invalid
} }
} }
this.emit() this.emit()
} }
console.log('[archive] total marked ids:', this.markedIds.size)
} catch (err) { } catch (err) {
// Non-blocking fetch; ignore errors here // Non-blocking fetch; ignore errors here
console.warn('[archive] start() error:', err)
} }
} }
} }