From acddff79f06e5a0272cb3b9e144da0abb1970cf2 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Fri, 11 Apr 2025 08:41:50 -0700 Subject: [PATCH] Improve loading a bit --- src/app/state.ts | 8 +++----- src/routes/+layout.svelte | 12 +++++++----- src/routes/spaces/[relay]/+layout.svelte | 14 +++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/app/state.ts b/src/app/state.ts index 518dbc0f..73d31ac4 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -61,7 +61,7 @@ import { walkThunks, signer, Router, - loadWithAsapMetaRelayUrls, + makeOutboxLoader, routerContext, appContext, } from "@welshman/app" @@ -332,8 +332,7 @@ export const { name: "settings", store: settings, getKey: settings => settings.event.pubkey, - load: (pubkey: string, relays: string[]) => - loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [SETTINGS], authors: [pubkey]}]), + load: makeOutboxLoader([SETTINGS]), }) // Alerts @@ -410,8 +409,7 @@ export const { name: "memberships", store: memberships, getKey: list => list.event.pubkey, - load: (pubkey: string, relays: string[]) => - loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [GROUPS], authors: [pubkey]}]), + load: makeOutboxLoader([GROUPS]), }) // Chats diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 215104cf..4e1fecce 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -7,7 +7,7 @@ import {dev} from "$app/environment" import {goto} from "$app/navigation" import {bytesToHex, hexToBytes} from "@noble/hashes/utils" - import {identity, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib" + import {identity, memoize, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib" import type {TrustedEvent, StampedEvent} from "@welshman/util" import {WRAP} from "@welshman/util" import {Nip46Broker, getPubkey, makeSecret} from "@welshman/signer" @@ -152,10 +152,12 @@ // Listen for space data, populate space-based notifications let unsubSpaces: any - userMembership.subscribe($membership => { - unsubSpaces?.() - unsubSpaces = listenForNotifications() - }) + userMembership.subscribe( + memoize($membership => { + unsubSpaces?.() + unsubSpaces = listenForNotifications() + }), + ) // Listen for chats, populate chat-based notifications let chatsReq: any diff --git a/src/routes/spaces/[relay]/+layout.svelte b/src/routes/spaces/[relay]/+layout.svelte index 2181a6e2..2d382664 100644 --- a/src/routes/spaces/[relay]/+layout.svelte +++ b/src/routes/spaces/[relay]/+layout.svelte @@ -2,8 +2,8 @@ import {onMount} from "svelte" import {page} from "$app/stores" import {ago, MONTH} from "@welshman/lib" - import {GROUPS, THREAD, COMMENT, MESSAGE, DELETE} from "@welshman/util" - import {request, load} from "@welshman/net" + import {GROUPS, THREAD, COMMENT, MESSAGE} from "@welshman/util" + import {request} from "@welshman/net" import Page from "@lib/components/Page.svelte" import SecondaryNav from "@lib/components/SecondaryNav.svelte" import MenuSpace from "@app/components/MenuSpace.svelte" @@ -54,11 +54,7 @@ const relays = [url] const since = ago(MONTH) - // Load all groups for this space to populate navigation. It would be nice to sync, but relay29 - // is too picky about how requests are built. - load({relays, filters: [{kinds: [GROUPS]}]}) - - // Load threads, comments, and recent messages for user rooms to help with a quick page transition + // Load groups, threads, comments, and recent messages for user rooms to help with a quick page transition pullConservatively({ relays, filters: [ @@ -68,8 +64,8 @@ ], }) - // Listen for deletes that would apply to messages we already have, and new groups - const req = request({relays, filters: [{kinds: [DELETE, GROUPS], since}]}) + // Completely refresh our groups list and listen for new ones + const req = request({relays, filters: [{kinds: [GROUPS]}]}) return () => { req.close()