mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
chore: remove debug console.log statements
Remove all debug console.log statements that were added during article loading and caching implementation, keeping only error and warning logs for actual error handling.
This commit is contained in:
@@ -75,13 +75,10 @@ export function useArticleLoader({
|
|||||||
|
|
||||||
// First check: naddr is required
|
// First check: naddr is required
|
||||||
if (!naddr) {
|
if (!naddr) {
|
||||||
console.log('[article-loader] Skipping load - missing naddr')
|
|
||||||
setReaderContent(undefined)
|
setReaderContent(undefined)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[article-loader] Starting load for naddr:', naddr)
|
|
||||||
|
|
||||||
// Clear readerContent immediately to prevent showing stale content from previous article
|
// Clear readerContent immediately to prevent showing stale content from previous article
|
||||||
// This ensures images from previous articles don't flash briefly
|
// This ensures images from previous articles don't flash briefly
|
||||||
setReaderContent(undefined)
|
setReaderContent(undefined)
|
||||||
@@ -91,15 +88,9 @@ export function useArticleLoader({
|
|||||||
// and fixes the race condition where relayPool isn't ready yet
|
// and fixes the race condition where relayPool isn't ready yet
|
||||||
let foundInCache = false
|
let foundInCache = false
|
||||||
try {
|
try {
|
||||||
console.log('[article-loader] Checking localStorage cache...')
|
|
||||||
// Check localStorage cache first (synchronous, doesn't need relayPool)
|
// Check localStorage cache first (synchronous, doesn't need relayPool)
|
||||||
const cachedArticle = getFromCache(naddr)
|
const cachedArticle = getFromCache(naddr)
|
||||||
if (cachedArticle) {
|
if (cachedArticle) {
|
||||||
console.log('[article-loader] ✅ Cache HIT - loading from localStorage', {
|
|
||||||
title: cachedArticle.title,
|
|
||||||
hasMarkdown: !!cachedArticle.markdown,
|
|
||||||
markdownLength: cachedArticle.markdown?.length
|
|
||||||
})
|
|
||||||
foundInCache = true
|
foundInCache = true
|
||||||
const title = cachedArticle.title || 'Untitled Article'
|
const title = cachedArticle.title || 'Untitled Article'
|
||||||
setCurrentTitle(title)
|
setCurrentTitle(title)
|
||||||
@@ -123,7 +114,6 @@ export function useArticleLoader({
|
|||||||
// Preload image if available to ensure it's cached by Service Worker
|
// Preload image if available to ensure it's cached by Service Worker
|
||||||
// This ensures images are available when offline
|
// This ensures images are available when offline
|
||||||
if (cachedArticle.image) {
|
if (cachedArticle.image) {
|
||||||
console.log('[article-loader] Preloading image for offline access:', cachedArticle.image)
|
|
||||||
preloadImage(cachedArticle.image)
|
preloadImage(cachedArticle.image)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,10 +164,7 @@ export function useArticleLoader({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return early - we have cached content, no need to query relays
|
// Return early - we have cached content, no need to query relays
|
||||||
console.log('[article-loader] Returning early with cached content')
|
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
console.log('[article-loader] ❌ Cache MISS - not found in localStorage')
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// If cache check fails, fall through to async loading
|
// If cache check fails, fall through to async loading
|
||||||
@@ -187,23 +174,15 @@ export function useArticleLoader({
|
|||||||
// Check EventStore synchronously (also doesn't need relayPool)
|
// Check EventStore synchronously (also doesn't need relayPool)
|
||||||
let foundInEventStore = false
|
let foundInEventStore = false
|
||||||
if (eventStore && !foundInCache) {
|
if (eventStore && !foundInCache) {
|
||||||
console.log('[article-loader] Checking EventStore...')
|
|
||||||
try {
|
try {
|
||||||
// Decode naddr to get the coordinate
|
// Decode naddr to get the coordinate
|
||||||
const decoded = nip19.decode(naddr)
|
const decoded = nip19.decode(naddr)
|
||||||
if (decoded.type === 'naddr') {
|
if (decoded.type === 'naddr') {
|
||||||
const pointer = decoded.data as AddressPointer
|
const pointer = decoded.data as AddressPointer
|
||||||
const coordinate = `${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`
|
const coordinate = `${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`
|
||||||
console.log('[article-loader] Looking for event with coordinate:', coordinate)
|
|
||||||
const storedEvent = eventStore.getEvent?.(coordinate)
|
const storedEvent = eventStore.getEvent?.(coordinate)
|
||||||
if (storedEvent) {
|
if (storedEvent) {
|
||||||
foundInEventStore = true
|
foundInEventStore = true
|
||||||
console.log('[article-loader] ✅ EventStore HIT - found event', {
|
|
||||||
id: storedEvent.id,
|
|
||||||
kind: storedEvent.kind,
|
|
||||||
hasContent: !!storedEvent.content,
|
|
||||||
contentLength: storedEvent.content?.length
|
|
||||||
})
|
|
||||||
const title = Helpers.getArticleTitle(storedEvent) || 'Untitled Article'
|
const title = Helpers.getArticleTitle(storedEvent) || 'Untitled Article'
|
||||||
setCurrentTitle(title)
|
setCurrentTitle(title)
|
||||||
const image = Helpers.getArticleImage(storedEvent)
|
const image = Helpers.getArticleImage(storedEvent)
|
||||||
@@ -262,10 +241,7 @@ export function useArticleLoader({
|
|||||||
|
|
||||||
// Return early - we have EventStore content, no need to query relays yet
|
// Return early - we have EventStore content, no need to query relays yet
|
||||||
// But we might want to fetch from relays in background if relayPool becomes available
|
// But we might want to fetch from relays in background if relayPool becomes available
|
||||||
console.log('[article-loader] Returning early with EventStore content')
|
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
console.log('[article-loader] ❌ EventStore MISS - no event found for coordinate:', coordinate)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -276,7 +252,6 @@ export function useArticleLoader({
|
|||||||
|
|
||||||
// Only return early if we have no content AND no relayPool to fetch from
|
// Only return early if we have no content AND no relayPool to fetch from
|
||||||
if (!relayPool && !foundInCache && !foundInEventStore) {
|
if (!relayPool && !foundInCache && !foundInEventStore) {
|
||||||
console.log('[article-loader] No relayPool available and no cached content - showing loading skeleton')
|
|
||||||
setReaderLoading(true)
|
setReaderLoading(true)
|
||||||
setReaderContent(undefined)
|
setReaderContent(undefined)
|
||||||
return
|
return
|
||||||
@@ -284,16 +259,13 @@ export function useArticleLoader({
|
|||||||
|
|
||||||
// If we have relayPool, proceed with async loading
|
// If we have relayPool, proceed with async loading
|
||||||
if (!relayPool) {
|
if (!relayPool) {
|
||||||
console.log('[article-loader] Waiting for relayPool to become available...')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadArticle = async () => {
|
const loadArticle = async () => {
|
||||||
const requestId = ++currentRequestIdRef.current
|
const requestId = ++currentRequestIdRef.current
|
||||||
console.log('[article-loader] Starting async loadArticle function', { requestId })
|
|
||||||
|
|
||||||
if (!mountedRef.current) {
|
if (!mountedRef.current) {
|
||||||
console.log('[article-loader] Component unmounted, aborting')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +282,6 @@ export function useArticleLoader({
|
|||||||
// At this point, we've checked EventStore and cache - neither had content
|
// At this point, we've checked EventStore and cache - neither had content
|
||||||
// Only show loading skeleton if we also don't have preview data
|
// Only show loading skeleton if we also don't have preview data
|
||||||
if (previewData) {
|
if (previewData) {
|
||||||
console.log('[article-loader] Using preview data (no skeleton)', { title: previewData.title })
|
|
||||||
// If we have preview data from navigation, show it immediately (no skeleton!)
|
// If we have preview data from navigation, show it immediately (no skeleton!)
|
||||||
setCurrentTitle(previewData.title)
|
setCurrentTitle(previewData.title)
|
||||||
setReaderContent({
|
setReaderContent({
|
||||||
@@ -324,13 +295,11 @@ export function useArticleLoader({
|
|||||||
setReaderLoading(false) // Turn off loading immediately - we have the preview!
|
setReaderLoading(false) // Turn off loading immediately - we have the preview!
|
||||||
} else {
|
} else {
|
||||||
// No cache, no EventStore, no preview data - need to load from relays
|
// No cache, no EventStore, no preview data - need to load from relays
|
||||||
console.log('[article-loader] ⚠️ No cache, EventStore, or preview - showing loading skeleton and querying relays')
|
|
||||||
setReaderLoading(true)
|
setReaderLoading(true)
|
||||||
setReaderContent(undefined)
|
setReaderContent(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('[article-loader] Querying relays for article...')
|
|
||||||
// Decode naddr to filter
|
// Decode naddr to filter
|
||||||
const decoded = nip19.decode(naddr)
|
const decoded = nip19.decode(naddr)
|
||||||
if (decoded.type !== 'naddr') {
|
if (decoded.type !== 'naddr') {
|
||||||
@@ -342,35 +311,20 @@ export function useArticleLoader({
|
|||||||
authors: [pointer.pubkey],
|
authors: [pointer.pubkey],
|
||||||
'#d': [pointer.identifier]
|
'#d': [pointer.identifier]
|
||||||
}
|
}
|
||||||
console.log('[article-loader] Relay query filter:', filter)
|
|
||||||
|
|
||||||
let firstEmitted = false
|
let firstEmitted = false
|
||||||
let latestEvent: NostrEvent | null = null
|
let latestEvent: NostrEvent | null = null
|
||||||
|
|
||||||
// Stream local-first via queryEvents; rely on EOSE (no timeouts)
|
// Stream local-first via queryEvents; rely on EOSE (no timeouts)
|
||||||
console.log('[article-loader] Starting queryEvents...')
|
|
||||||
const events = await queryEvents(relayPool, filter, {
|
const events = await queryEvents(relayPool, filter, {
|
||||||
onEvent: (evt) => {
|
onEvent: (evt) => {
|
||||||
if (!mountedRef.current) {
|
if (!mountedRef.current) {
|
||||||
console.log('[article-loader] Component unmounted during event stream, ignoring')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (currentRequestIdRef.current !== requestId) {
|
if (currentRequestIdRef.current !== requestId) {
|
||||||
console.log('[article-loader] Request ID mismatch, ignoring event', {
|
|
||||||
currentRequestId: currentRequestIdRef.current,
|
|
||||||
eventRequestId: requestId
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[article-loader] 📨 Received event from relay', {
|
|
||||||
id: evt.id,
|
|
||||||
kind: evt.kind,
|
|
||||||
created_at: evt.created_at,
|
|
||||||
contentLength: evt.content?.length,
|
|
||||||
isFirst: !firstEmitted
|
|
||||||
})
|
|
||||||
|
|
||||||
// Store in event store for future local reads
|
// Store in event store for future local reads
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@@ -386,7 +340,6 @@ export function useArticleLoader({
|
|||||||
|
|
||||||
// Emit immediately on first event
|
// Emit immediately on first event
|
||||||
if (!firstEmitted) {
|
if (!firstEmitted) {
|
||||||
console.log('[article-loader] ✅ First event received - updating UI immediately')
|
|
||||||
firstEmitted = true
|
firstEmitted = true
|
||||||
const title = Helpers.getArticleTitle(evt) || 'Untitled Article'
|
const title = Helpers.getArticleTitle(evt) || 'Untitled Article'
|
||||||
const image = Helpers.getArticleImage(evt)
|
const image = Helpers.getArticleImage(evt)
|
||||||
@@ -424,35 +377,19 @@ export function useArticleLoader({
|
|||||||
|
|
||||||
// Preload image to ensure it's cached by Service Worker
|
// Preload image to ensure it's cached by Service Worker
|
||||||
if (image) {
|
if (image) {
|
||||||
console.log('[article-loader] Preloading image for offline access:', image)
|
|
||||||
preloadImage(image)
|
preloadImage(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[article-loader] UI updated with first event and saved to cache')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('[article-loader] QueryEvents completed', {
|
|
||||||
eventCount: events.length,
|
|
||||||
hasLatestEvent: !!latestEvent,
|
|
||||||
mounted: mountedRef.current,
|
|
||||||
requestIdMatch: currentRequestIdRef.current === requestId
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!mountedRef.current || currentRequestIdRef.current !== requestId) {
|
if (!mountedRef.current || currentRequestIdRef.current !== requestId) {
|
||||||
console.log('[article-loader] Component unmounted or request ID changed, aborting')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalize with newest version if it's newer than what we first rendered
|
// Finalize with newest version if it's newer than what we first rendered
|
||||||
const finalEvent = (events.sort((a, b) => b.created_at - a.created_at)[0]) || latestEvent
|
const finalEvent = (events.sort((a, b) => b.created_at - a.created_at)[0]) || latestEvent
|
||||||
if (finalEvent) {
|
if (finalEvent) {
|
||||||
console.log('[article-loader] ✅ Finalizing with event', {
|
|
||||||
id: finalEvent.id,
|
|
||||||
created_at: finalEvent.created_at,
|
|
||||||
wasFirstEmitted: firstEmitted
|
|
||||||
})
|
|
||||||
const title = Helpers.getArticleTitle(finalEvent) || 'Untitled Article'
|
const title = Helpers.getArticleTitle(finalEvent) || 'Untitled Article'
|
||||||
const image = Helpers.getArticleImage(finalEvent)
|
const image = Helpers.getArticleImage(finalEvent)
|
||||||
const summary = Helpers.getArticleSummary(finalEvent)
|
const summary = Helpers.getArticleSummary(finalEvent)
|
||||||
@@ -479,7 +416,6 @@ export function useArticleLoader({
|
|||||||
// Note: We already saved from first event, so only save if this is different
|
// Note: We already saved from first event, so only save if this is different
|
||||||
if (!firstEmitted) {
|
if (!firstEmitted) {
|
||||||
// First event wasn't emitted, so save now
|
// First event wasn't emitted, so save now
|
||||||
console.log('[article-loader] Saving event to cache (first event was not emitted)')
|
|
||||||
const articleContent = {
|
const articleContent = {
|
||||||
title,
|
title,
|
||||||
markdown: finalEvent.content,
|
markdown: finalEvent.content,
|
||||||
@@ -490,21 +426,10 @@ export function useArticleLoader({
|
|||||||
event: finalEvent
|
event: finalEvent
|
||||||
}
|
}
|
||||||
saveToCache(naddr, articleContent)
|
saveToCache(naddr, articleContent)
|
||||||
} else {
|
|
||||||
// Cache was already saved when first event was received
|
|
||||||
console.log('[article-loader] Cache already saved from first event, skipping duplicate save')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[article-loader] ✅ Finalized with event from relays')
|
|
||||||
} else {
|
} else {
|
||||||
// As a last resort, fall back to the legacy helper (which includes cache)
|
// As a last resort, fall back to the legacy helper (which includes cache)
|
||||||
console.log('[article-loader] ⚠️ No events from relays, falling back to fetchArticleByNaddr')
|
|
||||||
const article = await fetchArticleByNaddr(relayPool, naddr, false, settingsRef.current)
|
const article = await fetchArticleByNaddr(relayPool, naddr, false, settingsRef.current)
|
||||||
console.log('[article-loader] fetchArticleByNaddr result:', {
|
|
||||||
hasArticle: !!article,
|
|
||||||
title: article?.title,
|
|
||||||
hasMarkdown: !!article?.markdown
|
|
||||||
})
|
|
||||||
if (!mountedRef.current || currentRequestIdRef.current !== requestId) return
|
if (!mountedRef.current || currentRequestIdRef.current !== requestId) return
|
||||||
setCurrentTitle(article.title)
|
setCurrentTitle(article.title)
|
||||||
setReaderContent({
|
setReaderContent({
|
||||||
|
|||||||
@@ -37,33 +37,19 @@ function getCacheKey(naddr: string): string {
|
|||||||
export function getFromCache(naddr: string): ArticleContent | null {
|
export function getFromCache(naddr: string): ArticleContent | null {
|
||||||
try {
|
try {
|
||||||
const cacheKey = getCacheKey(naddr)
|
const cacheKey = getCacheKey(naddr)
|
||||||
console.log('[article-cache] Checking cache with key:', cacheKey)
|
|
||||||
const cached = localStorage.getItem(cacheKey)
|
const cached = localStorage.getItem(cacheKey)
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
console.log('[article-cache] ❌ No cached entry found')
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const { content, timestamp }: CachedArticle = JSON.parse(cached)
|
const { content, timestamp }: CachedArticle = JSON.parse(cached)
|
||||||
const age = Date.now() - timestamp
|
const age = Date.now() - timestamp
|
||||||
console.log('[article-cache] Found cached entry', {
|
|
||||||
age: age,
|
|
||||||
ageDays: Math.floor(age / (24 * 60 * 60 * 1000)),
|
|
||||||
ttlDays: Math.floor(CACHE_TTL / (24 * 60 * 60 * 1000)),
|
|
||||||
isExpired: age > CACHE_TTL
|
|
||||||
})
|
|
||||||
|
|
||||||
if (age > CACHE_TTL) {
|
if (age > CACHE_TTL) {
|
||||||
console.log('[article-cache] ⚠️ Cache expired, removing')
|
|
||||||
localStorage.removeItem(cacheKey)
|
localStorage.removeItem(cacheKey)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[article-cache] ✅ Cache valid, returning content', {
|
|
||||||
title: content.title,
|
|
||||||
hasMarkdown: !!content.markdown,
|
|
||||||
markdownLength: content.markdown?.length
|
|
||||||
})
|
|
||||||
return content
|
return content
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('[article-cache] Error reading cache:', err)
|
console.warn('[article-cache] Error reading cache:', err)
|
||||||
@@ -112,20 +98,12 @@ export function saveToCache(naddr: string, content: ArticleContent, settings?: U
|
|||||||
// Note: settings parameter reserved for future use
|
// Note: settings parameter reserved for future use
|
||||||
void settings // Mark as intentionally unused for now
|
void settings // Mark as intentionally unused for now
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const cacheKey = getCacheKey(naddr)
|
const cacheKey = getCacheKey(naddr)
|
||||||
console.log('[article-cache] 💾 Saving to cache', {
|
|
||||||
key: cacheKey,
|
|
||||||
title: content.title,
|
|
||||||
hasMarkdown: !!content.markdown,
|
|
||||||
markdownLength: content.markdown?.length
|
|
||||||
})
|
|
||||||
const cached: CachedArticle = {
|
const cached: CachedArticle = {
|
||||||
content,
|
content,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
}
|
}
|
||||||
localStorage.setItem(cacheKey, JSON.stringify(cached))
|
localStorage.setItem(cacheKey, JSON.stringify(cached))
|
||||||
console.log('[article-cache] ✅ Successfully saved to cache')
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handle quota exceeded errors specifically
|
// Handle quota exceeded errors specifically
|
||||||
if (err instanceof DOMException && (err.code === 22 || err.code === 1014 || err.name === 'QuotaExceededError')) {
|
if (err instanceof DOMException && (err.code === 22 || err.code === 1014 || err.name === 'QuotaExceededError')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user