From 78d9b8da55140a200c78270055a22ad498ff130f Mon Sep 17 00:00:00 2001 From: Sandwich <299465+dskvr@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:01:13 +0700 Subject: [PATCH] fix most of the memory leaks in feeds, need to find a solution for observe --- apps/gui/package.json | 2 +- apps/gui/rollup.config.js | 30 ------ .../lib/components/partials/Debugger.svelte | 2 +- .../src/lib/components/partials/Feed.svelte | 9 +- .../lib/components/partials/FeedNote.svelte | 63 +++++------ .../partials/FeedNoteComments.svelte | 14 +++ .../partials/FeedNoteReactions.svelte | 14 +++ .../components/partials/FeedNoteZaps.svelte | 47 ++++++++ .../components/partials/MonitorActions.svelte | 6 +- .../components/partials/OperatorRelays.svelte | 21 ++-- .../gui/src/lib/services/FeedService/index.ts | 7 +- .../src/lib/stores/helpers/helpers-relay.ts | 21 ++-- apps/gui/src/lib/utils/lifecycle.ts | 2 +- apps/gui/src/lib/utils/ux.ts | 32 ++++-- .../relays/[protocol]/[...relay]/+page.svelte | 36 ++++--- .../[...relay]/components/RelayAudits.svelte | 3 +- apps/gui/vite.production.js | 3 +- apps/nocapd/docker-compose.gluetun.yaml | 48 +++++++++ internal/announce/.gitignore | 1 + internal/announce/dist/index.d.ts | 27 +++++ internal/announce/dist/index.js | 101 ++++++++++++++++++ .../src/NostrSqliteAdapter.ts | 4 + .../NostrToolsAdapter/src/NostrToolsWorker.ts | 2 +- 23 files changed, 375 insertions(+), 120 deletions(-) create mode 100644 apps/gui/src/lib/components/partials/FeedNoteComments.svelte create mode 100644 apps/gui/src/lib/components/partials/FeedNoteReactions.svelte create mode 100644 apps/gui/src/lib/components/partials/FeedNoteZaps.svelte create mode 100644 apps/nocapd/docker-compose.gluetun.yaml create mode 100644 internal/announce/.gitignore create mode 100644 internal/announce/dist/index.d.ts create mode 100644 internal/announce/dist/index.js diff --git a/apps/gui/package.json b/apps/gui/package.json index afd4b658..ddbb2168 100755 --- a/apps/gui/package.json +++ b/apps/gui/package.json @@ -1,7 +1,7 @@ { "name": "@nostrwatch/gui", "description": "", - "version": "0.6.23", + "version": "0.6.24", "license": "MIT", "keywords": [ "svelte", diff --git a/apps/gui/rollup.config.js b/apps/gui/rollup.config.js index 95028106..6525b7e0 100644 --- a/apps/gui/rollup.config.js +++ b/apps/gui/rollup.config.js @@ -64,35 +64,5 @@ export default [ watch: { clearScreen: false } - }, - { - treeshake: production, - input: 'src/main.js', - output: { - sourcemap: true, - format: 'iife', - name: 'app', - file: 'public/build/bundle.js', - inlineDynamicImports: true - }, - plugins: [ - svelte({ - compilerOptions: { - dev: !production - } - }), - css({ output: 'bundle.css' }), - resolve({ - browser: true, - dedupe: ['svelte', '@nostrwatch/route66', '@nostrwatch/route66-cacheadapter-dexieetl', '@nostrwatch/route66-wsadapter-nostrtools'], - exportConditions: ['svelte'] - }), - commonjs(), - !production && livereload('public'), - production && terser() - ], - watch: { - clearScreen: false - } } ]; diff --git a/apps/gui/src/lib/components/partials/Debugger.svelte b/apps/gui/src/lib/components/partials/Debugger.svelte index 948485ad..d28025af 100644 --- a/apps/gui/src/lib/components/partials/Debugger.svelte +++ b/apps/gui/src/lib/components/partials/Debugger.svelte @@ -126,7 +126,7 @@ addDebug('route66:websocketAdapter', $route66?.websocketAdapter.isReady? true: false); addDebug('route66:initialized', $route66?.initialized? true: false); addDebug('route66:numSubscriptions', $route66?.websocketAdapter?.subscriptions.size); - addDebug('route66:subscriptions', Array.from($route66?.websocketAdapter?.subscriptions)); + // addDebug('route66:subscriptions', Array.from($route66?.websocketAdapter?.subscriptions)); } const debugCacheAdapter = async () => { diff --git a/apps/gui/src/lib/components/partials/Feed.svelte b/apps/gui/src/lib/components/partials/Feed.svelte index c3a421e6..ebaa625c 100644 --- a/apps/gui/src/lib/components/partials/Feed.svelte +++ b/apps/gui/src/lib/components/partials/Feed.svelte @@ -29,7 +29,7 @@ const busy: Writable = writable(false); let items: Readable | undefined; - let [minColWidth, maxColWidth, gap] = [300, 500, 21] + let [minColWidth, maxColWidth, gap] = [400, 600, 21] let width:number, height: number const lastItemId = () => { @@ -54,7 +54,10 @@ } const destroy = () => { - $feedService!.unsubscribeAll(); + $feedService!.unsubscribeAll().then( () => { + $feedService!.destroy(); + feedService.set(null) + }); resumer?.() } @@ -71,8 +74,6 @@ {/if} - {$items?.length} - {#if $feedService && $items?.length} ; - const comments: Readable = noteCommentsCount$(note.id, memoryRelay); - const zaps: Readable = noteZaps$(note.id, memoryRelay); - const reactions: Readable = noteReactionsCount$(note.id, memoryRelay); - let content: Writable; const mount = () => { @@ -46,44 +44,24 @@ $: isComment = note.isComment $: user = pubkeyUserInstance(note.pubkey) $: name = user?.name || user?.pubkey - // $: animationClass = $relativesFetched? 'animate' : '' - $: bolt11s = $zaps.map(zap => { - const b11 = zap.tags.find(tag => tag[0] === 'bolt11')?.[1] - if(!b11) return null - return Bolt11.decode(b11) - }).filter( b11 => b11 !== null ) - $: zapSum = isVisible? abbrNum( - Math - .round( - bolt11s - .reduce((acc, b11) => acc += parseInt( - b11.sections.find( - section => section?.name === 'amount')?.value || "0" - ) - , 0) - /1000 - ) - ): ''; let isVisible: boolean = true; $: actionsClass = isVisible? '' : 'opacity-0'; - function abbrNum(num: number): string { - if(num === 0) return ''; - if (num < 1000) return num.toString(); - const units = ["", "K", "M", "B", "T", "P", "E"]; - const magnitude = Math.floor(Math.log10(num) / 3); - const precision = magnitude - 1; - const scaled = num / Math.pow(1000, magnitude); - return `${scaled.toFixed(precision + 1)}${units[magnitude]}`; - } + let commentsCountCache: number | undefined; + let reactionsCountCache: number | undefined; + let zapSumCache: string = '';
{ + isVisible = event.detail.isIntersecting; + }} >
@@ -106,22 +84,31 @@ {@html $content}
- {#if isVisible}
- {$reactions? $reactions : ''} + {#if isVisible} + + {:else} + {reactionsCountCache? reactionsCountCache : ''} + {/if}
- {zapSum} + {#if isVisible} + + {:else} + {zapSumCache? zapSumCache : ''} + {/if}
🗨 - {$comments? $comments : ''} + {#if isVisible} + + {:else} + {commentsCountCache? commentsCountCache : ''} + {/if}
- {/if}
-