refactor: remove event caches
This commit is contained in:
@ -4,19 +4,14 @@ import {
|
|||||||
NostrEvent,
|
NostrEvent,
|
||||||
NostrSystem,
|
NostrSystem,
|
||||||
ProfileLoaderService,
|
ProfileLoaderService,
|
||||||
ReqFilter,
|
|
||||||
socialGraphInstance,
|
socialGraphInstance,
|
||||||
TaggedNostrEvent,
|
|
||||||
} from "@snort/system";
|
} from "@snort/system";
|
||||||
import * as Comlink from "comlink";
|
|
||||||
|
|
||||||
import { RelayMetrics, SystemDb, UserCache, UserRelays } from "@/Cache";
|
import { RelayMetrics, SystemDb, UserCache, UserRelays } from "@/Cache";
|
||||||
import { addEventToFuzzySearch } from "@/Db/FuzzySearch";
|
import { addEventToFuzzySearch } from "@/Db/FuzzySearch";
|
||||||
import IndexedDBWorker from "@/Db/IndexedDB?worker";
|
|
||||||
import { LoginStore } from "@/Utils/Login";
|
import { LoginStore } from "@/Utils/Login";
|
||||||
import { hasWasm, WasmOptimizer } from "@/Utils/wasm";
|
import { hasWasm, WasmOptimizer } from "@/Utils/wasm";
|
||||||
|
|
||||||
export const indexedDB = Comlink.wrap(new IndexedDBWorker());
|
|
||||||
/**
|
/**
|
||||||
* Singleton nostr system
|
* Singleton nostr system
|
||||||
*/
|
*/
|
||||||
@ -39,30 +34,8 @@ System.on("auth", async (c, r, cb) => {
|
|||||||
System.on("event", (_, ev) => {
|
System.on("event", (_, ev) => {
|
||||||
addEventToFuzzySearch(ev);
|
addEventToFuzzySearch(ev);
|
||||||
socialGraphInstance.handleEvent(ev);
|
socialGraphInstance.handleEvent(ev);
|
||||||
if (CONFIG.useIndexedDBEvents && socialGraphInstance.getFollowDistance(ev.pubkey) <= 2) {
|
|
||||||
indexedDB.handleEvent(ev);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
System.on("request", (filter: ReqFilter) => {
|
|
||||||
if (CONFIG.useIndexedDBEvents) {
|
|
||||||
indexedDB.find(
|
|
||||||
filter,
|
|
||||||
Comlink.proxy((e: TaggedNostrEvent) => {
|
|
||||||
System.HandleEvent(e);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (CONFIG.useIndexedDBEvents) {
|
|
||||||
// load all profiles
|
|
||||||
indexedDB.find(
|
|
||||||
{ kinds: [0] },
|
|
||||||
Comlink.proxy((e: TaggedNostrEvent) => System.HandleEvent(e)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add profile loader fn
|
* Add profile loader fn
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +26,6 @@ import { RelayCache, RelayMetadataLoader } from "./outbox-model";
|
|||||||
import { Optimizer, DefaultOptimizer } from "./query-optimizer";
|
import { Optimizer, DefaultOptimizer } from "./query-optimizer";
|
||||||
import { trimFilters } from "./request-trim";
|
import { trimFilters } from "./request-trim";
|
||||||
import { NostrConnectionPool } from "./nostr-connection-pool";
|
import { NostrConnectionPool } from "./nostr-connection-pool";
|
||||||
import inMemoryDB from "./InMemoryDB";
|
|
||||||
|
|
||||||
export interface NostrSystemEvents {
|
export interface NostrSystemEvents {
|
||||||
change: (state: SystemSnapshot) => void;
|
change: (state: SystemSnapshot) => void;
|
||||||
@ -168,7 +167,6 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
|||||||
|
|
||||||
// internal handler for on-event
|
// internal handler for on-event
|
||||||
this.on("event", (sub, ev) => {
|
this.on("event", (sub, ev) => {
|
||||||
inMemoryDB.handleEvent(ev);
|
|
||||||
for (const [, v] of this.Queries) {
|
for (const [, v] of this.Queries) {
|
||||||
v.handleEvent(sub, ev);
|
v.handleEvent(sub, ev);
|
||||||
}
|
}
|
||||||
@ -318,22 +316,6 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
|||||||
}
|
}
|
||||||
qSend.filters = fNew;
|
qSend.filters = fNew;
|
||||||
|
|
||||||
fNew.forEach(f => {
|
|
||||||
const alreadyHave = inMemoryDB.findArray(f).map(e => {
|
|
||||||
this.HandleEvent(e);
|
|
||||||
return e.id;
|
|
||||||
});
|
|
||||||
if (alreadyHave.length) {
|
|
||||||
f.not = f.not ?? {};
|
|
||||||
if (f.not.ids) {
|
|
||||||
f.not.ids.push(...alreadyHave);
|
|
||||||
} else {
|
|
||||||
f.not.ids = alreadyHave;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.emit("request", f);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (qSend.relay) {
|
if (qSend.relay) {
|
||||||
this.#log("Sending query to %s %O", qSend.relay, qSend);
|
this.#log("Sending query to %s %O", qSend.relay, qSend);
|
||||||
const s = this.#pool.getConnection(qSend.relay);
|
const s = this.#pool.getConnection(qSend.relay);
|
||||||
|
Reference in New Issue
Block a user