feat: worker-relay delete

fix: worker-relay insert replacable events duplicate
This commit is contained in:
2024-05-23 11:59:48 +01:00
parent bb5bf34fe9
commit b764cc1535
15 changed files with 271 additions and 138 deletions

View File

@ -4,11 +4,11 @@
"dependencies": {
"@cashu/cashu-ts": "^1.0.0-rc.3",
"@here/maps-api-for-javascript": "^1.50.0",
"@noble/curves": "^1.0.0",
"@noble/hashes": "^1.3.3",
"@scure/base": "^1.1.1",
"@scure/bip32": "^1.3.0",
"@scure/bip39": "^1.1.1",
"@noble/curves": "^1.4.0",
"@noble/hashes": "^1.4.0",
"@scure/base": "^1.1.6",
"@scure/bip32": "^1.4.0",
"@scure/bip39": "^1.3.0",
"@snort/shared": "workspace:*",
"@snort/system": "workspace:*",
"@snort/system-react": "workspace:*",
@ -16,7 +16,7 @@
"@snort/system-web": "workspace:*",
"@snort/wallet": "workspace:*",
"@snort/worker-relay": "workspace:*",
"@szhsin/react-menu": "^3.3.1",
"@szhsin/react-menu": "^3.5.3",
"@uidotdev/usehooks": "^2.4.1",
"@void-cat/api": "^1.0.12",
"classnames": "^2.3.2",
@ -102,7 +102,7 @@
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@vitejs/plugin-react": "^4.2.0",
"@webbtc/webln-types": "^2.1.0",
"@webbtc/webln-types": "^3.0.0",
"@webscopeio/react-textarea-autocomplete": "^4.9.2",
"@welldone-software/why-did-you-render": "^8.0.1",
"autoprefixer": "^10.4.16",

View File

@ -0,0 +1,59 @@
import { NostrEvent, TaggedNostrEvent } from "@snort/system";
import { SnortContext } from "@snort/system-react";
import { useContext, useState } from "react";
import AsyncButton from "@/Components/Button/AsyncButton";
export function DebugPage() {
const system = useContext(SnortContext);
const [filter, setFilter] = useState("");
const [event, setEvent] = useState("");
const [results, setResult] = useState<Array<TaggedNostrEvent>>([]);
async function search() {
if (filter && system.cacheRelay) {
const r = await system.cacheRelay.query(["REQ", "test", JSON.parse(filter)]);
setResult(r.map(a => ({ ...a, relays: [] })));
}
}
async function insert() {
if (event && system.cacheRelay) {
const r = await system.cacheRelay.event(JSON.parse(event) as NostrEvent);
setResult([
{
content: JSON.stringify(r),
} as unknown as TaggedNostrEvent,
]);
}
}
async function removeEvents() {
if (filter && system.cacheRelay) {
const r = await system.cacheRelay.delete(["REQ", "delete-events", JSON.parse(filter)]);
setResult(r.map(a => ({ id: a }) as TaggedNostrEvent));
}
}
return (
<div className="flex flex-col gap-2">
<h3>Cache Query</h3>
<textarea value={filter} onChange={e => setFilter(e.target.value)} placeholder="nostr filter" />
<AsyncButton onClick={() => search()}>Query</AsyncButton>
<AsyncButton onClick={() => removeEvents()} className="!bg-red-500">
Delete
</AsyncButton>
<h3>Manual Insert</h3>
<textarea value={event} onChange={e => setEvent(e.target.value)} placeholder="nostr event" />
<AsyncButton onClick={() => insert()}>Insert</AsyncButton>
<div className="p-4 overflow-hidden">
<h4>Results: {results.length}</h4>
{results?.map(a => (
<pre key={a.id} className="text-mono text-xs text-pretty">
{JSON.stringify(a, undefined, 2)}
</pre>
))}
</div>
</div>
);
}

View File

@ -1,6 +1,7 @@
import { FeedCache } from "@snort/shared";
import { ReactNode, useEffect, useState, useSyncExternalStore } from "react";
import { FormattedMessage, FormattedNumber } from "react-intl";
import { useNavigate } from "react-router-dom";
import { GiftsCache, Relay, RelayMetrics } from "@/Cache";
import AsyncButton from "@/Components/Button/AsyncButton";
@ -32,7 +33,6 @@ function CacheDetails<T>({ cache, name }: { cache: FeedCache<T>; name: ReactNode
<small>
<FormattedMessage
defaultMessage="{count} ({count2} in memory)"
id="geppt8"
values={{
count: <FormattedNumber value={cache.keysOnTable().length} />,
count2: <FormattedNumber value={snapshot.length} />,
@ -53,6 +53,7 @@ function RelayCacheStats() {
const [counts, setCounts] = useState<Record<string, number>>({});
const [myEvents, setMyEvents] = useState<number>(0);
const login = useLogin();
const navigate = useNavigate();
useEffect(() => {
Relay.summary().then(setCounts);
@ -69,7 +70,6 @@ function RelayCacheStats() {
<p>
<FormattedMessage
defaultMessage="My events: {n}"
id="lEnclp"
values={{
n: <FormattedNumber value={myEvents} />,
}}
@ -124,6 +124,9 @@ function RelayCacheStats() {
}}>
<FormattedMessage defaultMessage="Dump" />
</AsyncButton>
<AsyncButton onClick={() => navigate("/cache-debug")}>
<FormattedMessage defaultMessage="Debug" />
</AsyncButton>
</div>
</div>
);

View File

@ -13,6 +13,7 @@ import { IntlProvider } from "@/Components/IntlProvider/IntlProvider";
import { db } from "@/Db";
import { addCachedMetadataToFuzzySearch } from "@/Db/FuzzySearch";
import { AboutPage } from "@/Pages/About";
import { DebugPage } from "@/Pages/CacheDebug";
import { SnortDeckLayout } from "@/Pages/Deck/DeckLayout";
import DonatePage from "@/Pages/Donate/DonatePage";
import ErrorPage from "@/Pages/ErrorPage";
@ -74,6 +75,10 @@ async function initSite() {
let didInit = false;
const mainRoutes = [
...RootRoutes,
{
path: "/cache-debug",
element: <DebugPage />,
},
{
path: "/help",
element: <HelpPage />,