LRUCache ParsedZaps, import from system dir in worker
continuous-integration/drone/push Build is running Details

This commit is contained in:
Martti Malmi 2024-02-05 11:20:13 +02:00
parent a97e895cb8
commit aefe8a8210
5 changed files with 16 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { NostrEvent } from "nostr";
import { NostrEvent } from "../nostr";
import { DexieTableLike, FeedCache } from "@snort/shared";
export class EventsCache extends FeedCache<NostrEvent> {

View File

@ -1,4 +1,4 @@
import { ReqFilter } from "nostr";
import { ReqFilter } from "./nostr";
/**
* Remove empty filters, filters which would result in no results

View File

@ -24,8 +24,8 @@ import { CachedTable } from "@snort/shared";
import { EventsCache } from "../cache/events";
import { RelayMetricHandler } from "../relay-metric-handler";
import debug from "debug";
import { ConnectionPool } from "connection-pool";
import { CacheRelay } from "cache-relay";
import { ConnectionPool } from "../connection-pool";
import { CacheRelay } from "../cache-relay";
export class SystemWorker extends EventEmitter<NostrSystemEvents> implements SystemInterface {
#log = debug("SystemWorker");

View File

@ -4,9 +4,10 @@ import { findTag } from "./utils";
import { EventExt } from "./event-ext";
import { NostrLink } from "./nostr-link";
import debug from "debug";
import {LRUCache} from "lru-cache";
const Log = debug("zaps");
const ParsedZapCache = new Map<string, ParsedZap>();
const ParsedZapCache = new LRUCache<string, ParsedZap>({ max: 1000 });
function getInvoice(zap: NostrEvent): InvoiceDetails | undefined {
const bolt11 = findTag(zap, "bolt11");

View File

@ -1,7 +1,12 @@
import { NostrEvent, parseZap } from "@snort/system";
import debug from "debug";
import { RelayHandler } from "./types";
import { RelayHandler, NostrEvent } from "./types";
// import { parseZap } from "../../system/src/zaps";
// placeholder:
const parseZap = (_zap: NostrEvent) => {
return { event: null } as { event: null | NostrEvent };
}
const log = debug("getForYouFeed");
@ -58,7 +63,7 @@ async function getMyReactedEvents(relay: RelayHandler, pubkey: string) {
kinds: [1, 6, 7, 9735],
}) as NostrEvent[];
myEvents.forEach(ev => {
const targetEventId = ev.kind === 9735 ? parseZap(ev).event?.id : ev.tags.find(tag => tag[0] === "e")?.[1];
const targetEventId = ev.kind === 9735 ? parseZap(ev).event?.id : ev.tags.find((tag: string[]) => tag[0] === "e")?.[1];
if (targetEventId) {
myReactedEventIds.add(targetEventId);
}
@ -101,7 +106,7 @@ async function getEventIdsReactedByOthers(
// NIP-113 NOT filter could improve performance by not selecting these events in the first place
return;
}
event.tags.forEach(tag => {
event.tags.forEach((tag: string[]) => {
if (tag[0] === "e") {
const score = Math.ceil(Math.sqrt(othersWhoReacted.get(event.pubkey) || 0));
eventIdsReactedByOthers.set(tag[1], (eventIdsReactedByOthers.get(tag[1]) || 0) + score);
@ -150,7 +155,7 @@ async function getFeedEvents(
});
// Filter out replies
const filteredEvents = events.filter(ev => !ev.tags.some(tag => tag[0] === "e"));
const filteredEvents = events.filter(ev => !ev.tags.some((tag: string[]) => tag[0] === "e"));
// Define constants for normalization
// const recentnessWeight = -1;