My scenario is very simple. I just subscribe with a query filter of a my pubkey. When I test the subscription, the event is handled multiple times times, naturally due to receiving the evemt from multiple relays.

I was wondering if there is any tooling in the SDK that helpsanage the same event, and if not, I was going to just use a set, like you mentioned, to avoid the bot replying multiple times for each handle

Reply to this note

Please Login to reply.

Discussion

I’d use a queue for inbound events and then you can pull from that queue using a worker type flow and then add the event id to a set, after doing a membership test to see if you’ve already processed the event.

Alternatively, since the set will grow in size forever (between restarts), you’ll either need to persist the set data (like Redis) or use a LRU cache or something like a ring buffer. Or perhaps a bloom filter if an occasional false positive is ok.

It all kind of depends during what time frame do you expect the duplicate events. Over an hour window, or days, or months, etc. Is reprocessing an event forbidden. And how many events or relay sources.

Literal seconds, I would imagine.