mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
when in pool, automatically and efficiently deduplicate.
This commit is contained in:
11
pool.ts
11
pool.ts
@@ -1,5 +1,8 @@
|
||||
import {Relay, relayInit} from './relay'
|
||||
import {normalizeURL} from './utils'
|
||||
import {Filter} from './filter'
|
||||
import {Event} from './event'
|
||||
import {SubscriptionOptions, Sub} from './relay'
|
||||
|
||||
export function pool(defaultRelays: string[] = []) {
|
||||
return new SimplePool(defaultRelays)
|
||||
@@ -22,6 +25,14 @@ class SimplePool {
|
||||
const hasEventId = (id: string): boolean => this._knownIds.has(id)
|
||||
const relay = relayInit(nm, hasEventId)
|
||||
this._conn[nm] = relay
|
||||
|
||||
let sub = relay.sub
|
||||
relay.sub = (filters: Filter[], opts?: SubscriptionOptions): Sub => {
|
||||
let s = sub(filters, opts)
|
||||
s.on('event', (event: Event) => this._knownIds.add(event.id as string))
|
||||
return s
|
||||
}
|
||||
|
||||
return relay
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user