mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
debug: add detailed logging to fetchProfiles function
Add comprehensive logs prefixed with [fetch-profiles] to track: - How many profiles are requested - Cache lookup results - Relay query configuration - Each profile event as it's received - Summary of fetched vs missing profiles - Which profiles weren't found on relays This will help diagnose why only 9/19 profiles are being returned.
This commit is contained in:
@@ -194,10 +194,12 @@ export const fetchProfiles = async (
|
||||
): Promise<NostrEvent[]> => {
|
||||
try {
|
||||
if (pubkeys.length === 0) {
|
||||
console.log(`[fetch-profiles] No pubkeys provided`)
|
||||
return []
|
||||
}
|
||||
|
||||
const uniquePubkeys = Array.from(new Set(pubkeys))
|
||||
console.log(`[fetch-profiles] Requested ${pubkeys.length} profiles (${uniquePubkeys.length} unique)`)
|
||||
|
||||
// First, check localStorage cache for all requested profiles
|
||||
const cachedProfiles = loadCachedProfiles(uniquePubkeys)
|
||||
@@ -210,11 +212,16 @@ export const fetchProfiles = async (
|
||||
eventStore.add(profile)
|
||||
}
|
||||
|
||||
console.log(`[fetch-profiles] Found ${cachedProfiles.size} profiles in cache`)
|
||||
|
||||
// Determine which pubkeys need to be fetched from relays
|
||||
const pubkeysToFetch = uniquePubkeys.filter(pubkey => !cachedProfiles.has(pubkey))
|
||||
|
||||
console.log(`[fetch-profiles] Need to fetch ${pubkeysToFetch.length} profiles from relays`)
|
||||
|
||||
// If all profiles are cached, return early
|
||||
if (pubkeysToFetch.length === 0) {
|
||||
console.log(`[fetch-profiles] All profiles cached, returning ${profilesByPubkey.size} profiles`)
|
||||
return Array.from(profilesByPubkey.values())
|
||||
}
|
||||
|
||||
@@ -223,7 +230,13 @@ export const fetchProfiles = async (
|
||||
const prioritized = prioritizeLocalRelays(relayUrls)
|
||||
const { local: localRelays, remote: remoteRelays } = partitionRelays(prioritized)
|
||||
|
||||
console.log(`[fetch-profiles] Querying ${localRelays.length} local relays and ${remoteRelays.length} remote relays`)
|
||||
let eventCount = 0
|
||||
const fetchedPubkeys = new Set<string>()
|
||||
|
||||
const processEvent = (event: NostrEvent) => {
|
||||
eventCount++
|
||||
fetchedPubkeys.add(event.pubkey)
|
||||
const existing = profilesByPubkey.get(event.pubkey)
|
||||
if (!existing || event.created_at > existing.created_at) {
|
||||
profilesByPubkey.set(event.pubkey, event)
|
||||
@@ -231,6 +244,9 @@ export const fetchProfiles = async (
|
||||
eventStore.add(event)
|
||||
// Cache to localStorage for future use
|
||||
cacheProfile(event)
|
||||
console.log(`[fetch-profiles] Received profile for ${event.pubkey.slice(0, 16)}... (event #${eventCount})`)
|
||||
} else {
|
||||
console.log(`[fetch-profiles] Received older profile for ${event.pubkey.slice(0, 16)}..., keeping existing`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +275,13 @@ export const fetchProfiles = async (
|
||||
await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
||||
|
||||
const profiles = Array.from(profilesByPubkey.values())
|
||||
|
||||
console.log(`[fetch-profiles] Fetch completed: received ${eventCount} events, ${fetchedPubkeys.size} unique profiles`)
|
||||
const missingPubkeys = pubkeysToFetch.filter(p => !fetchedPubkeys.has(p))
|
||||
if (missingPubkeys.length > 0) {
|
||||
console.warn(`[fetch-profiles] ${missingPubkeys.length} profiles not found on relays:`, missingPubkeys.map(p => p.slice(0, 16) + '...'))
|
||||
}
|
||||
console.log(`[fetch-profiles] Returning ${profiles.length} total profiles (${cachedProfiles.size} cached + ${fetchedPubkeys.size} fetched)`)
|
||||
|
||||
// Note: We don't preload all profile images here to avoid ERR_INSUFFICIENT_RESOURCES
|
||||
// Profile images will be cached by Service Worker when they're actually displayed.
|
||||
@@ -273,7 +296,7 @@ export const fetchProfiles = async (
|
||||
|
||||
return profiles
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch profiles:', error)
|
||||
console.error('[fetch-profiles] Failed to fetch profiles:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user