refactor: move inMemoryDb hook
This commit is contained in:
@ -10,8 +10,6 @@ import { NostrEvent, ReqCommand, ReqFilter, TaggedNostrEvent, u256 } from "./nos
|
||||
import { RelayInfo } from "./relay-info";
|
||||
import EventKind from "./event-kind";
|
||||
import { EventExt } from "./event-ext";
|
||||
import { getHex64 } from "./utils";
|
||||
import inMemoryDB from "./InMemoryDB";
|
||||
|
||||
/**
|
||||
* Relay settings
|
||||
@ -203,21 +201,6 @@ 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
|
||||
/* there's some problem in retrieval from inMemoryDB? try disabling for now
|
||||
const msgId = getHex64(e.data as string, "id");
|
||||
if (inMemoryDB.has(msgId)) {
|
||||
console.log("already have");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
const id = getHex64(e.data as string, "id");
|
||||
if (inMemoryDB.has(id)) {
|
||||
this.#log("Already have, skip processing %s", id);
|
||||
return;
|
||||
}
|
||||
|
||||
const msg = JSON.parse(e.data as string) as Array<string | NostrEvent | boolean>;
|
||||
const tag = msg[0] as string;
|
||||
switch (tag) {
|
||||
|
@ -24,7 +24,6 @@ import { RelayMetadataLoader } from "./outbox-model";
|
||||
import { Optimizer, DefaultOptimizer } from "./query-optimizer";
|
||||
import { ConnectionPool, DefaultConnectionPool } from "./connection-pool";
|
||||
import { QueryManager } from "./query-manager";
|
||||
import inMemoryDB from "./InMemoryDB";
|
||||
|
||||
export interface NostrSystemEvents {
|
||||
change: (state: SystemSnapshot) => void;
|
||||
@ -123,7 +122,6 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
||||
this.pool.on("event", (_, sub, ev) => {
|
||||
ev.relays?.length && this.relayMetricsHandler.onEvent(ev.relays[0]);
|
||||
this.emit("event", sub, ev);
|
||||
inMemoryDB.handleEvent(ev);
|
||||
});
|
||||
this.pool.on("disconnect", (id, code) => {
|
||||
const c = this.pool.getConnection(id);
|
||||
@ -192,7 +190,6 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
||||
}
|
||||
|
||||
HandleEvent(subId: string, ev: TaggedNostrEvent) {
|
||||
inMemoryDB.handleEvent(ev);
|
||||
this.emit("event", subId, ev);
|
||||
this.#queryManager.handleEvent(ev);
|
||||
}
|
||||
|
Reference in New Issue
Block a user