Skip to content

Commit

Permalink
Delete unused cache
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowCait committed Oct 10, 2023
1 parent a7b1447 commit d6cacfd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
5 changes: 2 additions & 3 deletions web/src/lib/cache/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<pubkey, Metadata>());

// <event.id, event>
export const cachedEvents = new Map<id, Event>();
// <event.pubkey, event>
export const metadataEvents = new Map<pubkey, Event>();
export const metadataStore = writable(new Map<pubkey, Metadata>());
// <root-id, event>
export const channelMetadataEvents = new Map<id, Event>();

Expand Down
8 changes: 3 additions & 5 deletions web/src/lib/timelines/MainTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions web/src/stores/UserEvents.ts
Original file line number Diff line number Diff line change
@@ -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<Map<string, UserEvent>> = writable(new Map());
function saveUserEvent(userEvent: UserEvent) {
Expand All @@ -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;
});
}
Expand Down

0 comments on commit d6cacfd

Please sign in to comment.