use LRUSet to skip already seen event processing
This commit is contained in:
@ -9,6 +9,8 @@ import { ConnectionStats } from "./connection-stats";
|
||||
import { NostrEvent, ReqCommand, ReqFilter, TaggedNostrEvent, u256 } from "./nostr";
|
||||
import { RelayInfo } from "./relay-info";
|
||||
import EventKind from "./event-kind";
|
||||
import seenEvents from "./seen-events";
|
||||
import {getHex64} from "./utils";
|
||||
|
||||
/**
|
||||
* Relay settings
|
||||
@ -199,6 +201,14 @@ export class Connection extends EventEmitter<ConnectionEvents> {
|
||||
OnMessage(e: WebSocket.MessageEvent) {
|
||||
this.#activity = unixNowMs();
|
||||
if ((e.data as string).length > 0) {
|
||||
// skip message processing if we've already seen it
|
||||
const msgId = getHex64(e.data as string, "id");
|
||||
if (seenEvents.has(msgId)) {
|
||||
console.log('already seen');
|
||||
return;
|
||||
}
|
||||
seenEvents.add(msgId); // TODO only do after msg validation
|
||||
|
||||
const msg = JSON.parse(e.data as string) as Array<string | NostrEvent | boolean>;
|
||||
const tag = msg[0] as string;
|
||||
switch (tag) {
|
||||
|
Reference in New Issue
Block a user