refactor: move inMemoryDb hook

This commit is contained in:
Kieran 2024-01-19 10:09:36 +00:00
parent 0307bacd30
commit 2b1cf34424
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 2 additions and 20 deletions

View File

@ -1,5 +1,6 @@
import { removeUndefined, throwIfOffline } from "@snort/shared";
import { mapEventToProfile, NostrEvent, NostrSystem, ProfileLoaderService, socialGraphInstance } from "@snort/system";
import inMemoryDB from "@snort/system/src/InMemoryDB";
import { EventsCache, Relay, RelayMetrics, SystemDb, UserCache, UserRelays } from "@/Cache";
import { LoginStore } from "@/Utils/Login";
@ -29,6 +30,7 @@ System.on("event", (_, ev) => {
Relay.event(ev);
EventsCache.discover(ev);
UserCache.discover(ev);
inMemoryDB.handleEvent(ev);
socialGraphInstance.handleEvent(ev);
});

View File

@ -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) {

View File

@ -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);
}