From d0d0503a1311711d1c4240729525bef2a5e3fa73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Fri, 13 Jan 2023 00:01:18 +0800 Subject: [PATCH] perf: fetch instance info only once --- composables/users.ts | 16 ++++++++++------ package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/composables/users.ts b/composables/users.ts index 14a6f4c3..143f5b82 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -1,4 +1,4 @@ -import { login as loginMasto } from 'masto' +import { createClient, fetchV1Instance } from 'masto' import type { mastodon } from 'masto' import type { Ref } from 'vue' import type { MaybeComputedRef, RemovableRef } from '@vueuse/core' @@ -106,22 +106,26 @@ async function loginTo(user?: Omit & { account?: mastodon. const route = useRoute() const router = useRouter() const server = user?.server || route.params.server as string || publicServer.value - const masto = await loginMasto({ - url: `https://${server}`, + const url = `https://${server}` + const instance = await fetchV1Instance({ + url, + }) + const masto = await createClient({ + url, + streamingApiUrl: instance.urls.streamingApi, accessToken: user?.token, disableVersionCheck: true, }) if (!user?.token) { publicServer.value = server - publicInstance.value = await masto.v1.instances.fetch() + publicInstance.value = instance } else { try { - const [me, instance, pushSubscription] = await Promise.all([ + const [me, pushSubscription] = await Promise.all([ masto.v1.accounts.verifyCredentials(), - masto.v1.instances.fetch(), // if PWA is not enabled, don't get push subscription useRuntimeConfig().public.pwaEnabled // we get 404 response instead empty data diff --git a/package.json b/package.json index 1f449cf0..45c09f78 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "iso-639-1": "^2.1.15", "js-yaml": "^4.1.0", "lru-cache": "^7.14.1", - "masto": "^5.2.0", + "masto": "^5.3.0", "pinia": "^2.0.28", "shiki": "^0.12.1", "shiki-es": "^0.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 59d9efd2..a1e113f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -94,7 +94,7 @@ importers: jsdom: ^21.0.0 lint-staged: ^13.1.0 lru-cache: ^7.14.1 - masto: ^5.2.0 + masto: ^5.3.0 nuxt: ^3.0.0 pinia: ^2.0.28 postcss-nested: ^6.0.0 @@ -152,7 +152,7 @@ importers: iso-639-1: 2.1.15 js-yaml: 4.1.0 lru-cache: 7.14.1 - masto: 5.2.0 + masto: 5.3.0 pinia: 2.0.28_typescript@4.9.4 shiki: 0.12.1 shiki-es: 0.1.2 @@ -8049,8 +8049,8 @@ packages: resolution: {integrity: sha512-Z1NL3Tb1M9wH4XESsCDEksWoKTdlUafKc4pt0GRwjUyXaCFZ+dc3g2erqB6zm3szA2IUSi7VnPI+o/9jnxh9hw==} dev: true - /masto/5.2.0: - resolution: {integrity: sha512-71pKUdPZDuQSPJqRJSwsZ/QqvO/arOkdRyXEyOdeU9QukQ30OEW1M9BCGBp/b9Lbf6R7d9oCCdefmxXCSAzlFg==} + /masto/5.3.0: + resolution: {integrity: sha512-gArycufHuEEQ6WCvWNmiIQq+AIAo2grWQwO7mpenNKb0wFKYSaYTeMthx0t+Ircso+vBtsXdbjGMfzZeIttlow==} dependencies: '@mastojs/ponyfills': 1.0.4 change-case: 4.1.2