Browse Source

Performance improvements

Default show only 30040 events
default 100 root events
master
limina1 9 months ago
parent
commit
02998318c3
  1. 2
      src/lib/components/EventLimitControl.svelte
  2. 2
      src/lib/navigator/EventNetwork/Settings.svelte
  3. 2
      src/lib/state.ts
  4. 27
      src/routes/visualize/+page.svelte

2
src/lib/components/EventLimitControl.svelte

@ -37,7 +37,7 @@
type="number" type="number"
id="event-limit" id="event-limit"
min="1" min="1"
max="50" max="200"
class="w-20 bg-primary-0 dark:bg-primary-1000 border border-gray-300 dark:border-gray-700 rounded-md px-2 py-1 dark:text-white" class="w-20 bg-primary-0 dark:bg-primary-1000 border border-gray-300 dark:border-gray-700 rounded-md px-2 py-1 dark:text-white"
bind:value={inputValue} bind:value={inputValue}
on:input={handleInput} on:input={handleInput}

2
src/lib/navigator/EventNetwork/Settings.svelte

@ -154,7 +154,7 @@
</Button> </Button>
</div> </div>
{#if eventTypesExpanded} {#if eventTypesExpanded}
<EventKindFilter /> <EventKindFilter onReload={onupdate} />
{/if} {/if}
</div> </div>

2
src/lib/state.ts

@ -11,5 +11,5 @@ export const tabBehaviour: Writable<string> = writable(
export const userPublickey: Writable<string> = writable( export const userPublickey: Writable<string> = writable(
(browser && localStorage.getItem("wikinostr_loggedInPublicKey")) || "", (browser && localStorage.getItem("wikinostr_loggedInPublicKey")) || "",
); );
export const networkFetchLimit: Writable<number> = writable(20); export const networkFetchLimit: Writable<number> = writable(100);
export const levelsToRender: Writable<number> = writable(3); export const levelsToRender: Writable<number> = writable(3);

27
src/routes/visualize/+page.svelte

@ -6,6 +6,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte"; import { onMount } from "svelte";
import { get } from "svelte/store";
import EventNetwork from "$lib/navigator/EventNetwork/index.svelte"; import EventNetwork from "$lib/navigator/EventNetwork/index.svelte";
import { ndkInstance } from "$lib/ndk"; import { ndkInstance } from "$lib/ndk";
import type { NDKEvent } from "@nostr-dev-kit/ndk"; import type { NDKEvent } from "@nostr-dev-kit/ndk";
@ -57,6 +58,14 @@
error = null; error = null;
let validIndexEvents: Set<NDKEvent>; let validIndexEvents: Set<NDKEvent>;
// Check if index events (30040) are enabled
// Use get() to read store value in non-reactive context
const config = get(visualizationConfig);
const enabledKinds = config.allowedKinds.filter(
kind => !config.disabledKinds.includes(kind)
);
const shouldFetchIndex = enabledKinds.includes(INDEX_EVENT_KIND);
if (data.eventId) { if (data.eventId) {
// Fetch specific publication // Fetch specific publication
@ -72,6 +81,9 @@
} }
validIndexEvents = new Set([event]); validIndexEvents = new Set([event]);
} else if (!shouldFetchIndex) {
debug("Index events (30040) are disabled, skipping fetch");
validIndexEvents = new Set();
} else { } else {
// Original behavior: fetch all publications // Original behavior: fetch all publications
debug(`Fetching index events (kind ${INDEX_EVENT_KIND})`); debug(`Fetching index events (kind ${INDEX_EVENT_KIND})`);
@ -120,15 +132,20 @@
debug("Content references to fetch:", contentReferences.size); debug("Content references to fetch:", contentReferences.size);
// Step 4: Fetch the referenced content events with author filter // Step 4: Fetch the referenced content events with author filter
debug(`Fetching content events (kinds ${CONTENT_EVENT_KINDS.join(', ')})`); // Only fetch content kinds that are enabled
const enabledContentKinds = CONTENT_EVENT_KINDS.filter(kind => enabledKinds.includes(kind));
debug(`Fetching content events (enabled kinds: ${enabledContentKinds.join(', ')})`);
// Group by author to make more efficient queries // Group by author to make more efficient queries
const referencesByAuthor = new Map<string, Array<{ kind: number; dTag: string }>>(); const referencesByAuthor = new Map<string, Array<{ kind: number; dTag: string }>>();
contentReferences.forEach(({ kind, pubkey, dTag }) => { contentReferences.forEach(({ kind, pubkey, dTag }) => {
if (!referencesByAuthor.has(pubkey)) { // Only include references for enabled kinds
referencesByAuthor.set(pubkey, []); if (enabledContentKinds.includes(kind)) {
if (!referencesByAuthor.has(pubkey)) {
referencesByAuthor.set(pubkey, []);
}
referencesByAuthor.get(pubkey)!.push({ kind, dTag });
} }
referencesByAuthor.get(pubkey)!.push({ kind, dTag });
}); });
// Fetch events for each author // Fetch events for each author
@ -136,7 +153,7 @@
async ([author, refs]) => { async ([author, refs]) => {
const dTags = [...new Set(refs.map(r => r.dTag))]; // Dedupe d-tags const dTags = [...new Set(refs.map(r => r.dTag))]; // Dedupe d-tags
return $ndkInstance.fetchEvents({ return $ndkInstance.fetchEvents({
kinds: CONTENT_EVENT_KINDS, kinds: enabledContentKinds, // Only fetch enabled kinds
authors: [author], authors: [author],
"#d": dTags, "#d": dTags,
}); });

Loading…
Cancel
Save