Browse Source

Include profile events in visualization

- Update batchFetchProfiles to return fetched profile events
- Add fetched profile events to allEvents array
- Update profile stats to show actual count of fetched profiles
- Profile events are now properly tracked in event counts

This ensures kind 0 events show as green (loaded) and can be visualized in the graph.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
master
limina1 9 months ago
parent
commit
13e946eda3
  1. 10
      src/lib/utils/profileCache.ts
  2. 24
      src/routes/visualize/+page.svelte

10
src/lib/utils/profileCache.ts

@ -74,17 +74,20 @@ export async function getDisplayName(pubkey: string): Promise<string> { @@ -74,17 +74,20 @@ export async function getDisplayName(pubkey: string): Promise<string> {
* Batch fetches profiles for multiple pubkeys
* @param pubkeys - Array of public keys to fetch profiles for
* @param onProgress - Optional callback for progress updates
* @returns Array of profile events
*/
export async function batchFetchProfiles(
pubkeys: string[],
onProgress?: (fetched: number, total: number) => void
): Promise<void> {
): Promise<NDKEvent[]> {
const allProfileEvents: NDKEvent[] = [];
// Filter out already cached pubkeys
const uncachedPubkeys = pubkeys.filter(pk => !profileCache.has(pk));
if (uncachedPubkeys.length === 0) {
if (onProgress) onProgress(pubkeys.length, pubkeys.length);
return;
return allProfileEvents;
}
try {
@ -111,6 +114,7 @@ export async function batchFetchProfiles( @@ -111,6 +114,7 @@ export async function batchFetchProfiles(
try {
const content = JSON.parse(event.content);
profileCache.set(event.pubkey, content as ProfileData);
allProfileEvents.push(event);
fetchedCount++;
} catch (e) {
console.error("Failed to parse profile content:", e);
@ -128,6 +132,8 @@ export async function batchFetchProfiles( @@ -128,6 +132,8 @@ export async function batchFetchProfiles(
} catch (e) {
console.error("Failed to batch fetch profiles:", e);
}
return allProfileEvents;
}
/**

24
src/routes/visualize/+page.svelte

@ -518,13 +518,14 @@ @@ -518,13 +518,14 @@
});
// Fetch ALL profiles if kind 0 is enabled
let profileEvents: NDKEvent[] = [];
if (kind0Config) {
debug("Fetching profiles for all discovered pubkeys");
// Update progress during fetch
profileLoadingProgress = { current: 0, total: allPubkeys.size };
await batchFetchProfiles(
profileEvents = await batchFetchProfiles(
Array.from(allPubkeys),
(fetched, total) => {
profileLoadingProgress = { current: fetched, total };
@ -532,11 +533,14 @@ @@ -532,11 +533,14 @@
);
profileLoadingProgress = null;
debug("Profile fetch complete");
debug("Profile fetch complete, fetched", profileEvents.length, "profiles");
// Add profile events to allEvents
allEvents = [...allEvents, ...profileEvents];
// Update profile stats for display
profileStats = {
totalFetched: allPubkeys.size,
totalFetched: profileEvents.length,
displayLimit: kind0Config.limit
};
}
@ -815,17 +819,25 @@ @@ -815,17 +819,25 @@
// Fetch profiles for the new events
const newEvents = Array.from(fetchedEvents);
const newPubkeys = extractPubkeysFromEvents(newEvents);
if (newPubkeys.size > 0) {
let newProfileEvents: NDKEvent[] = [];
if (newPubkeys.size > 0 && $visualizationConfig.eventConfigs.some(ec => ec.kind === 0 && !$visualizationConfig.disabledKinds?.includes(0))) {
debug("Fetching profiles for", newPubkeys.size, "pubkeys from missing events");
profileLoadingProgress = { current: 0, total: newPubkeys.size };
await batchFetchProfiles(Array.from(newPubkeys), (fetched, total) => {
newProfileEvents = await batchFetchProfiles(Array.from(newPubkeys), (fetched, total) => {
profileLoadingProgress = { current: fetched, total };
});
profileLoadingProgress = null;
// Update profile stats
profileStats = {
totalFetched: profileStats.totalFetched + newProfileEvents.length,
displayLimit: profileStats.displayLimit
};
}
// Add to all events
allEvents = [...allEvents, ...newEvents];
allEvents = [...allEvents, ...newEvents, ...newProfileEvents];
// Re-apply display limits
events = filterByDisplayLimits(allEvents, $displayLimits);

Loading…
Cancel
Save