Remove duplicates from pull

This commit is contained in:
Jon Staab
2025-10-27 14:44:51 -07:00
parent e2bdb88cc2
commit 7d8f5e05b4
+9 -3
View File
@@ -1,6 +1,6 @@
import {EventEmitter} from "events"
import {on, sleep, randomId, groupBy, pushToMapKey, inc, flatten, chunk} from "@welshman/lib"
import {SignedEvent, Filter} from "@welshman/util"
import {SignedEvent, TrustedEvent, Filter} from "@welshman/util"
import {
RelayMessage,
isRelayNegErr,
@@ -201,7 +201,8 @@ export const pull = async ({context, ...options}: PullOptions) => {
}
}
const result: SignedEvent[] = []
const seen = new Set<string>()
const result: TrustedEvent[] = []
await Promise.all(
Array.from(idsByRelay.entries()).map(([relay, allIds]) => {
@@ -216,7 +217,12 @@ export const pull = async ({context, ...options}: PullOptions) => {
signal: options.signal,
autoClose: true,
onClose: resolve,
onEvent: event => result.push(event as SignedEvent),
onEvent: event => {
if (!seen.has(event.id)) {
seen.add(event.id)
result.push(event)
}
},
}),
),
),