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. 21
      src/routes/visualize/+page.svelte

2
src/lib/components/EventLimitControl.svelte

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
type="number"
id="event-limit"
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"
bind:value={inputValue}
on:input={handleInput}

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

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

2
src/lib/state.ts

@ -11,5 +11,5 @@ export const tabBehaviour: Writable<string> = writable( @@ -11,5 +11,5 @@ export const tabBehaviour: Writable<string> = writable(
export const userPublickey: Writable<string> = writable(
(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);

21
src/routes/visualize/+page.svelte

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
-->
<script lang="ts">
import { onMount } from "svelte";
import { get } from "svelte/store";
import EventNetwork from "$lib/navigator/EventNetwork/index.svelte";
import { ndkInstance } from "$lib/ndk";
import type { NDKEvent } from "@nostr-dev-kit/ndk";
@ -58,6 +59,14 @@ @@ -58,6 +59,14 @@
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) {
// Fetch specific publication
debug(`Fetching specific publication: ${data.eventId}`);
@ -72,6 +81,9 @@ @@ -72,6 +81,9 @@
}
validIndexEvents = new Set([event]);
} else if (!shouldFetchIndex) {
debug("Index events (30040) are disabled, skipping fetch");
validIndexEvents = new Set();
} else {
// Original behavior: fetch all publications
debug(`Fetching index events (kind ${INDEX_EVENT_KIND})`);
@ -120,15 +132,20 @@ @@ -120,15 +132,20 @@
debug("Content references to fetch:", contentReferences.size);
// 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
const referencesByAuthor = new Map<string, Array<{ kind: number; dTag: string }>>();
contentReferences.forEach(({ kind, pubkey, dTag }) => {
// Only include references for enabled kinds
if (enabledContentKinds.includes(kind)) {
if (!referencesByAuthor.has(pubkey)) {
referencesByAuthor.set(pubkey, []);
}
referencesByAuthor.get(pubkey)!.push({ kind, dTag });
}
});
// Fetch events for each author
@ -136,7 +153,7 @@ @@ -136,7 +153,7 @@
async ([author, refs]) => {
const dTags = [...new Set(refs.map(r => r.dTag))]; // Dedupe d-tags
return $ndkInstance.fetchEvents({
kinds: CONTENT_EVENT_KINDS,
kinds: enabledContentKinds, // Only fetch enabled kinds
authors: [author],
"#d": dTags,
});

Loading…
Cancel
Save