Stop opening duplicate WebSocket connections
The real problem: nostr.relay() and nostr.group() each open brand new
WebSocket connections outside the pool. Every hook that called these
was creating duplicate connections to relays the pool already had open.
Fixed by routing all queries and subscriptions through the pool (nostr)
directly, which reuses its internal connections:
- useStreamPosts: nostr.relay('wss://relay.ditto.pub') → nostr
- useStreamKind: nostr.relay('wss://relay.ditto.pub') → nostr
- useSearchProfiles: nostr.relay('wss://relay.ditto.pub') → nostr
- useFollowActions: nostr.group([...]) → nostr
- FollowPackDetailContent: nostr.group([...]) → nostr
Also reverted the hacky relay cleanup code in NostrProvider since
it was trying to solve the wrong problem.
Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
@@ -95,8 +95,6 @@ export function useStreamPosts(query: string, options: StreamPostsOptions) {
|
||||
setAllEvents(Array.from(eventMap.values()).sort((a, b) => b.created_at - a.created_at));
|
||||
}
|
||||
|
||||
const relay = nostr.relay('wss://relay.ditto.pub');
|
||||
|
||||
// Build the kinds list: either vines-only or kind 1 + enabled extras
|
||||
const kinds: number[] = isVines
|
||||
? [34236]
|
||||
@@ -108,10 +106,10 @@ export function useStreamPosts(query: string, options: StreamPostsOptions) {
|
||||
baseFilter.search = query.trim();
|
||||
}
|
||||
|
||||
// 1. Fetch initial batch
|
||||
// 1. Fetch initial batch (uses pool, reuses existing connections)
|
||||
(async () => {
|
||||
try {
|
||||
const events = await relay.query(
|
||||
const events = await nostr.query(
|
||||
[{ ...baseFilter, limit: 40 }],
|
||||
{ signal: ac.signal },
|
||||
);
|
||||
@@ -124,11 +122,11 @@ export function useStreamPosts(query: string, options: StreamPostsOptions) {
|
||||
if (alive) setIsLoading(false);
|
||||
})();
|
||||
|
||||
// 2. Stream new events
|
||||
// 2. Stream new events (uses pool, reuses existing connections)
|
||||
(async () => {
|
||||
try {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
for await (const msg of relay.req(
|
||||
for await (const msg of nostr.req(
|
||||
[{ ...baseFilter, since: now, limit: 100 }],
|
||||
{ signal: ac.signal },
|
||||
)) {
|
||||
|
||||
Reference in New Issue
Block a user