From 163d2dc355cba3db8536f8e2c5363fb67b31dd81 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Tue, 16 Jun 2026 15:00:01 -0700 Subject: [PATCH] Tweak outbox loader --- packages/client/src/blockedRelayLists.ts | 2 +- packages/client/src/blossom.ts | 2 +- packages/client/src/follows.ts | 2 +- packages/client/src/messagingRelayLists.ts | 2 +- packages/client/src/mutes.ts | 2 +- packages/client/src/pins.ts | 2 +- packages/client/src/profiles.ts | 2 +- packages/client/src/relayLists.ts | 40 +++++++--------------- packages/client/src/searchRelayLists.ts | 2 +- packages/net/src/request.ts | 2 +- 10 files changed, 22 insertions(+), 36 deletions(-) diff --git a/packages/client/src/blockedRelayLists.ts b/packages/client/src/blockedRelayLists.ts index 0c50f86..ce940d2 100644 --- a/packages/client/src/blockedRelayLists.ts +++ b/packages/client/src/blockedRelayLists.ts @@ -19,7 +19,7 @@ export class BlockedRelayLists extends RepositoryCollection getRelaysFromList(this.get(pubkey)) diff --git a/packages/client/src/blossom.ts b/packages/client/src/blossom.ts index afb86cc..c624db6 100644 --- a/packages/client/src/blossom.ts +++ b/packages/client/src/blossom.ts @@ -18,6 +18,6 @@ export class BlossomServerLists extends RepositoryCollection { } fetch(pubkey: string, relayHints: string[] = []) { - return this.ctx.use(RelayLists).makeOutboxLoader(MUTES)(pubkey, relayHints) + return this.ctx.use(RelayLists).loadUsingOutbox(pubkey, {kinds: [MUTES]}, relayHints) } } diff --git a/packages/client/src/pins.ts b/packages/client/src/pins.ts index 187dee7..0e454f6 100644 --- a/packages/client/src/pins.ts +++ b/packages/client/src/pins.ts @@ -18,6 +18,6 @@ export class PinLists extends RepositoryCollection> } fetch(pubkey: string, relayHints: string[] = []) { - return this.ctx.use(RelayLists).makeOutboxLoader(PINS)(pubkey, relayHints) + return this.ctx.use(RelayLists).loadUsingOutbox(pubkey, {kinds: [PINS]}, relayHints) } } diff --git a/packages/client/src/profiles.ts b/packages/client/src/profiles.ts index 7bc4a7c..166d83d 100644 --- a/packages/client/src/profiles.ts +++ b/packages/client/src/profiles.ts @@ -18,7 +18,7 @@ export class Profiles extends RepositoryCollection diff --git a/packages/client/src/relayLists.ts b/packages/client/src/relayLists.ts index 061192b..904ea08 100644 --- a/packages/client/src/relayLists.ts +++ b/packages/client/src/relayLists.ts @@ -5,7 +5,6 @@ import { asDecryptedEvent, readList, getRelaysFromList, - isPlainReplaceableKind, sortEventsDesc, } from "@welshman/util" import type {Filter, TrustedEvent, PublishedList} from "@welshman/util" @@ -16,9 +15,8 @@ import type {IClient} from "./client.js" /** * NIP-65 relay lists, keyed by pubkey. This is the routing substrate every other - * outbox-model load depends on, so it also exposes `loadUsingOutbox` / - * `makeOutboxLoader` for other collections to build their fetchers on. It and the - * Router reference each other lazily via `ctx.use`, so the cycle never bites. + * outbox-model load depends on, so it also exposes `loadUsingOutbox` for other + * collections to use as their fetcher. */ export class RelayLists extends RepositoryCollection { constructor(ctx: IClient) { @@ -31,34 +29,34 @@ export class RelayLists extends RepositoryCollection { fetch(pubkey: string, relayHints: string[] = []) { const filters = [{kinds: [RELAYS], authors: [pubkey], limit: 1}] + const networking = this.ctx.use(Networking) const router = this.ctx.use(Router) return Promise.all([ - this.ctx.use(Networking).load({filters, relays: router.FromRelays(relayHints).getUrls()}), - this.ctx.use(Networking).load({filters, relays: router.FromPubkey(pubkey).getUrls()}), - this.ctx.use(Networking).load({filters, relays: router.Index().getUrls()}), + networking.load({filters, relays: router.FromRelays(relayHints).getUrls()}), + networking.load({filters, relays: router.FromPubkey(pubkey).getUrls()}), + networking.load({filters, relays: router.Index().getUrls()}), ]) } getRelaysForPubkey = (pubkey: string, mode?: RelayMode) => getRelaysFromList(this.get(pubkey), mode) - // Load a pubkey's events using their advertised write relays (outbox model) + // Load a pubkey's events using their advertised write relays (outbox model), + // plus any explicit relay hints. This is the fetcher outbox-loaded collections + // (profiles, follows, mutes, …) delegate to — it's a stable method, so calling + // it doesn't build a fresh loader per call. - loadUsingOutbox = async (kind: number, pubkey: string, filter: Filter = {}) => { - const filters: Filter[] = [{...filter, kinds: [kind], authors: [pubkey]}] + loadUsingOutbox = async (pubkey: string, filter: Filter = {}, relayHints: string[] = []) => { + const filters: Filter[] = [{...filter, authors: [pubkey]}] const writeRelays = getRelaysFromList(await this.load(pubkey), RelayMode.Write) const allRelays = this.ctx .use(Router) - .FromRelays(writeRelays) + .FromRelays([...relayHints, ...writeRelays]) .policy(addMinimalFallbacks) .limit(8) .getUrls() - if (isPlainReplaceableKind(kind)) { - filters[0].limit = 1 - } - for (const relays of chunk(2, allRelays)) { const events = await this.ctx.use(Networking).load({filters, relays}) @@ -67,16 +65,4 @@ export class RelayLists extends RepositoryCollection { } } } - - makeOutboxLoader = - (kind: number, filter: Filter = {}) => - async (pubkey: string, relayHints: string[] = []) => { - const filters: Filter[] = [{...filter, kinds: [kind], authors: [pubkey]}] - const relays = this.ctx.use(Router).FromRelays(relayHints).getUrls() - - await Promise.all([ - this.ctx.use(Networking).load({filters, relays}), - this.loadUsingOutbox(kind, pubkey, filter), - ]) - } } diff --git a/packages/client/src/searchRelayLists.ts b/packages/client/src/searchRelayLists.ts index 90e52fa..5fad540 100644 --- a/packages/client/src/searchRelayLists.ts +++ b/packages/client/src/searchRelayLists.ts @@ -19,6 +19,6 @@ export class SearchRelayLists extends RepositoryCollection return allRequests.map(r => resultsByRequest.get(r) || []) }) as Loader -export const load = makeLoader({delay: 200, timeout: 3000, threshold: 0.5}) +export const load = makeLoader({delay: 30, timeout: 3000, threshold: 0.5})