From d6cacfd0d6f4bb215526725811e6e5cfab66a267 Mon Sep 17 00:00:00 2001 From: SnowCait Date: Tue, 10 Oct 2023 09:36:13 +0900 Subject: [PATCH] Delete unused cache --- web/src/lib/cache/Events.ts | 5 ++--- web/src/lib/timelines/MainTimeline.ts | 8 +++----- .../[npub=npub]/timeline/UserFollowingTimeline.svelte | 7 +------ web/src/stores/UserEvents.ts | 6 ------ 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/web/src/lib/cache/Events.ts b/web/src/lib/cache/Events.ts index 5ba3f0c33..dcb1f3727 100644 --- a/web/src/lib/cache/Events.ts +++ b/web/src/lib/cache/Events.ts @@ -4,11 +4,10 @@ import type { id, pubkey } from '$lib/Types'; import { EventItem, Metadata } from '$lib/Items'; import { events } from '../../stores/Events'; +export const metadataStore = writable(new Map()); + // export const cachedEvents = new Map(); -// -export const metadataEvents = new Map(); -export const metadataStore = writable(new Map()); // export const channelMetadataEvents = new Map(); diff --git a/web/src/lib/timelines/MainTimeline.ts b/web/src/lib/timelines/MainTimeline.ts index 348308404..e27be9b59 100644 --- a/web/src/lib/timelines/MainTimeline.ts +++ b/web/src/lib/timelines/MainTimeline.ts @@ -5,7 +5,7 @@ import { bufferTime } from 'rxjs'; import { timeout } from '$lib/Constants'; import { filterTags } from '$lib/EventHelper'; import { Metadata } from '$lib/Items'; -import { metadataEvents, metadataStore } from '../cache/Events'; +import { metadataStore } from '../cache/Events'; export const rxNostr = createRxNostr({ timeout }); // Based on NIP-65 @@ -26,10 +26,8 @@ rxNostr .use(metadataReq.pipe(bufferTime(1000, null, 10), batch())) .pipe(latestEach(({ event }: { event: Event }) => event.pubkey)) .subscribe(async (packet) => { - const cache = metadataEvents.get(packet.event.pubkey); - if (cache === undefined || cache.created_at < packet.event.created_at) { - metadataEvents.set(packet.event.pubkey, packet.event); - + const cache = get(metadataStore).get(packet.event.pubkey); + if (cache === undefined || cache.event.created_at < packet.event.created_at) { const metadata = new Metadata(packet.event); console.log('[rx-nostr metadata]', packet, metadata.content?.name); const store = get(metadataStore); diff --git a/web/src/routes/[npub=npub]/timeline/UserFollowingTimeline.svelte b/web/src/routes/[npub=npub]/timeline/UserFollowingTimeline.svelte index a5f5d738d..7607d6404 100644 --- a/web/src/routes/[npub=npub]/timeline/UserFollowingTimeline.svelte +++ b/web/src/routes/[npub=npub]/timeline/UserFollowingTimeline.svelte @@ -13,7 +13,6 @@ import { Kind, SimplePool, type Event, nip19 } from 'nostr-tools'; import { minTimelineLength, reverseChronologicalItem, timelineBufferMs } from '$lib/Constants'; import { rxNostr, metadataReqEmit } from '$lib/timelines/MainTimeline'; - import { metadataEvents } from '$lib/cache/Events'; import { EventItem } from '$lib/Items'; export let pubkey: string; @@ -23,11 +22,7 @@ let unsubscribe: () => void; export async function initialize() { - console.log( - '[user following timeline initialize]', - nip19.npubEncode(pubkey), - metadataEvents.get(pubkey)?.content - ); + console.log('[user following timeline initialize]', nip19.npubEncode(pubkey)); $items = []; if (unsubscribe !== undefined) { diff --git a/web/src/stores/UserEvents.ts b/web/src/stores/UserEvents.ts index 36d6de26f..f94e1fed4 100644 --- a/web/src/stores/UserEvents.ts +++ b/web/src/stores/UserEvents.ts @@ -1,7 +1,6 @@ import { writable, type Writable } from 'svelte/store'; import type { User, UserEvent } from '../routes/types'; import { nip57, type Event } from 'nostr-tools'; -import { metadataEvents } from '$lib/cache/Events'; export const userEvents: Writable> = writable(new Map()); function saveUserEvent(userEvent: UserEvent) { @@ -12,11 +11,6 @@ function saveUserEvent(userEvent: UserEvent) { userEvents.set(userEvent.pubkey, userEvent); } - const cache = metadataEvents.get(userEvent.pubkey); - if (cache === undefined || cache.created_at < userEvent.created_at) { - metadataEvents.set(userEvent.pubkey, userEvent); - } - return userEvents; }); }