optimize deduplication.

This commit is contained in:
fiatjaf 2023-03-01 16:39:18 -03:00 committed by Jonathan Staab
parent 1188dc55be
commit 1e270b52aa

View File

@ -263,17 +263,20 @@ const subscribe = async (
return
}
const sub = conn.nostr.sub(filter, {id})
const sub = conn.nostr.sub(filter, {
id,
alreadyHaveEvent: (id) => {
conn.stats.eventsCount += 1
let has = false
if (seen.has(id)) has = true
seen.add(id)
return has
}
})
sub.on('event', e => {
conn.stats.eventsCount += 1
if (!seen.has(e.id)) {
seen.add(e.id)
// Normalize events here, annotate with relay url
onEvent({...e, seen_on: relay.url, content: e.content || ''})
}
})
sub.on('eose', () => {