forked from Kieran/snort
use seenEvents in IndexedDB
This commit is contained in:
parent
287ce32690
commit
d31a03a565
@ -1,7 +1,7 @@
|
||||
import Dexie, { Table } from "dexie";
|
||||
import { TaggedNostrEvent, ReqFilter as Filter } from "@snort/system";
|
||||
import * as Comlink from "comlink";
|
||||
import LRUSet from "@snort/shared/src/LRUSet";
|
||||
import { seenEvents } from "@snort/system";
|
||||
|
||||
type Tag = {
|
||||
id: string;
|
||||
@ -16,7 +16,6 @@ class IndexedDB extends Dexie {
|
||||
events!: Table<TaggedNostrEvent>;
|
||||
tags!: Table<Tag>;
|
||||
private saveQueue: SaveQueueEntry[] = [];
|
||||
private seenEvents = new LRUSet<string>(1000);
|
||||
private subscribedEventIds = new Set<string>();
|
||||
private subscribedAuthors = new Set<string>();
|
||||
private subscribedTags = new Set<string>();
|
||||
@ -58,10 +57,10 @@ class IndexedDB extends Dexie {
|
||||
}
|
||||
|
||||
handleEvent(event: TaggedNostrEvent) {
|
||||
if (this.seenEvents.has(event.id)) {
|
||||
if (seenEvents.has(event.id)) {
|
||||
return;
|
||||
}
|
||||
this.seenEvents.add(event.id);
|
||||
seenEvents.add(event.id);
|
||||
|
||||
// maybe we don't want event.kind 3 tags
|
||||
const tags =
|
||||
@ -149,7 +148,7 @@ class IndexedDB extends Dexie {
|
||||
|
||||
// make sure only 1 argument is passed
|
||||
const cb = e => {
|
||||
this.seenEvents.add(e.id);
|
||||
seenEvents.add(e.id);
|
||||
callback(e);
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,7 @@ 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 { seenEvents } from "./seen-events";
|
||||
import {getHex64} from "./utils";
|
||||
|
||||
/**
|
||||
@ -204,7 +204,6 @@ export class Connection extends EventEmitter<ConnectionEvents> {
|
||||
// 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
|
||||
|
@ -33,6 +33,7 @@ export * from "./query-optimizer";
|
||||
export * from "./encrypted";
|
||||
export * from "./outbox-model";
|
||||
export { parseIMeta } from "./utils";
|
||||
export * from "./seen-events";
|
||||
|
||||
export * from "./impl/nip4";
|
||||
export * from "./impl/nip44";
|
||||
|
@ -1,3 +1,3 @@
|
||||
import LRUSet from "@snort/shared/src/LRUSet";
|
||||
|
||||
export default new LRUSet<string>(2000);
|
||||
export const seenEvents = new LRUSet<string>(2000);
|
Loading…
Reference in New Issue
Block a user