LRUCache ParsedZaps, import from system dir in worker
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
a97e895cb8
commit
aefe8a8210
2
packages/system/src/cache/events.ts
vendored
2
packages/system/src/cache/events.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { NostrEvent } from "nostr";
|
import { NostrEvent } from "../nostr";
|
||||||
import { DexieTableLike, FeedCache } from "@snort/shared";
|
import { DexieTableLike, FeedCache } from "@snort/shared";
|
||||||
|
|
||||||
export class EventsCache extends FeedCache<NostrEvent> {
|
export class EventsCache extends FeedCache<NostrEvent> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ReqFilter } from "nostr";
|
import { ReqFilter } from "./nostr";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove empty filters, filters which would result in no results
|
* Remove empty filters, filters which would result in no results
|
||||||
|
@ -24,8 +24,8 @@ import { CachedTable } from "@snort/shared";
|
|||||||
import { EventsCache } from "../cache/events";
|
import { EventsCache } from "../cache/events";
|
||||||
import { RelayMetricHandler } from "../relay-metric-handler";
|
import { RelayMetricHandler } from "../relay-metric-handler";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { ConnectionPool } from "connection-pool";
|
import { ConnectionPool } from "../connection-pool";
|
||||||
import { CacheRelay } from "cache-relay";
|
import { CacheRelay } from "../cache-relay";
|
||||||
|
|
||||||
export class SystemWorker extends EventEmitter<NostrSystemEvents> implements SystemInterface {
|
export class SystemWorker extends EventEmitter<NostrSystemEvents> implements SystemInterface {
|
||||||
#log = debug("SystemWorker");
|
#log = debug("SystemWorker");
|
||||||
|
@ -4,9 +4,10 @@ import { findTag } from "./utils";
|
|||||||
import { EventExt } from "./event-ext";
|
import { EventExt } from "./event-ext";
|
||||||
import { NostrLink } from "./nostr-link";
|
import { NostrLink } from "./nostr-link";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
|
import {LRUCache} from "lru-cache";
|
||||||
|
|
||||||
const Log = debug("zaps");
|
const Log = debug("zaps");
|
||||||
const ParsedZapCache = new Map<string, ParsedZap>();
|
const ParsedZapCache = new LRUCache<string, ParsedZap>({ max: 1000 });
|
||||||
|
|
||||||
function getInvoice(zap: NostrEvent): InvoiceDetails | undefined {
|
function getInvoice(zap: NostrEvent): InvoiceDetails | undefined {
|
||||||
const bolt11 = findTag(zap, "bolt11");
|
const bolt11 = findTag(zap, "bolt11");
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { NostrEvent, parseZap } from "@snort/system";
|
|
||||||
import debug from "debug";
|
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");
|
const log = debug("getForYouFeed");
|
||||||
|
|
||||||
@ -58,7 +63,7 @@ async function getMyReactedEvents(relay: RelayHandler, pubkey: string) {
|
|||||||
kinds: [1, 6, 7, 9735],
|
kinds: [1, 6, 7, 9735],
|
||||||
}) as NostrEvent[];
|
}) as NostrEvent[];
|
||||||
myEvents.forEach(ev => {
|
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) {
|
if (targetEventId) {
|
||||||
myReactedEventIds.add(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
|
// NIP-113 NOT filter could improve performance by not selecting these events in the first place
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.tags.forEach(tag => {
|
event.tags.forEach((tag: string[]) => {
|
||||||
if (tag[0] === "e") {
|
if (tag[0] === "e") {
|
||||||
const score = Math.ceil(Math.sqrt(othersWhoReacted.get(event.pubkey) || 0));
|
const score = Math.ceil(Math.sqrt(othersWhoReacted.get(event.pubkey) || 0));
|
||||||
eventIdsReactedByOthers.set(tag[1], (eventIdsReactedByOthers.get(tag[1]) || 0) + score);
|
eventIdsReactedByOthers.set(tag[1], (eventIdsReactedByOthers.get(tag[1]) || 0) + score);
|
||||||
@ -150,7 +155,7 @@ async function getFeedEvents(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Filter out replies
|
// 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
|
// Define constants for normalization
|
||||||
// const recentnessWeight = -1;
|
// const recentnessWeight = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user