From da6f4bab6a9734fef9100f8c068cdc938a896db6 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Fri, 15 Sep 2023 14:17:34 -0700 Subject: [PATCH] fix: decrease site fetches --- package.json | 2 +- src/lib/auth.ts | 17 ++++++++++++++++- src/lib/components/ui/Navbar.svelte | 2 +- src/lib/lemmy.ts | 6 ------ src/routes/+layout.svelte | 2 -- src/routes/+page.svelte | 27 ++++++++++++--------------- src/routes/+page.ts | 3 --- 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 27555c87..c1683c15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "1.6.5", + "version": "1.7.0", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/lib/auth.ts b/src/lib/auth.ts index dd55de9e..018531e6 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -5,7 +5,11 @@ import { getClient, site } from '$lib/lemmy.js' import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js' import { userSettings } from '$lib/settings.js' import { moveItem } from '$lib/util.js' -import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client' +import { + LemmyHttp, + type GetSiteResponse, + type MyUserInfo, +} from 'lemmy-js-client' import { get, writable } from 'svelte/store' const getDefaultProfile = (): Profile => ({ @@ -197,9 +201,20 @@ const serializeUser = (user: Profile): Profile => ({ user: undefined, }) +instance.subscribe(async (i) => { + try { + // fetching site is handled by auth.ts if logged in + if (get(profile)?.jwt) return + const s = await new LemmyHttp(`https://${i}`).getSite() + + site.set(s) + } catch (e) {} +}) + export async function setUserID(id: number) { const pd = get(profileData) if (id == -1) { + instance.set(DEFAULT_INSTANCE_URL) resetProfile() return } diff --git a/src/lib/components/ui/Navbar.svelte b/src/lib/components/ui/Navbar.svelte index 09a9c2b7..8e34f736 100644 --- a/src/lib/components/ui/Navbar.svelte +++ b/src/lib/components/ui/Navbar.svelte @@ -66,7 +66,7 @@ Powered by Photon diff --git a/src/lib/lemmy.ts b/src/lib/lemmy.ts index 36cc3864..0d28943a 100644 --- a/src/lib/lemmy.ts +++ b/src/lib/lemmy.ts @@ -39,12 +39,6 @@ export const getInstance = () => get(instance) export const site = writable(undefined) -if (LINKED_INSTANCE_URL) { - getClient(LINKED_INSTANCE_URL) - .getSite({}) - .then((s) => site.set(s)) -} - export async function validateInstance(instance: string): Promise { if (instance == '') return false diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 1b1409c4..2e7911c6 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -38,8 +38,6 @@ $: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : '' $: darkTheme = $theme && inDarkTheme() - $: console.log(darkTheme) - onMount(() => { if (browser) { window diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index f50975b7..7944fda2 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -10,6 +10,7 @@ import { GlobeAmericas, Icon } from 'svelte-hero-icons' import { profile } from '$lib/auth.js' import ViewSelect from '$lib/components/lemmy/ViewSelect.svelte' + import { site } from '$lib/lemmy.js' export let data @@ -23,13 +24,13 @@ About
- {#await data.streamed.site then site} + {#if $site} - {/await} + {/if}
@@ -75,22 +76,18 @@ diff --git a/src/routes/+page.ts b/src/routes/+page.ts index a82fd68f..7daa3ec6 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -27,9 +27,6 @@ export async function load({ url, fetch }) { type_: listingType, auth: get(profile)?.jwt, }), - streamed: { - site: getClient(undefined, fetch).getSite({}), - }, } } catch (err) { throw error(500, {