refactor(frontend): 非ログイン画面でのmeta取得を減らす (#13776)

* refactor(frontend): 非ログイン画面でのmeta取得を減らす

* fix(frontend): サーバー供給のmetaとクライアントフォールバックで取れるmetaの型が違うのを修正

* force fetch meta at welcome.vue

* refactor
This commit is contained in:
かっこかり 2024-05-01 13:51:00 +09:00 committed by GitHub
parent 2ff90a80d4
commit 2017f9114f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 40 deletions

View File

@ -4,19 +4,11 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<div v-if="meta" :class="$style.root" :style="{ backgroundImage: `url(${ meta.backgroundImageUrl })` }"></div> <div v-if="instance" :class="$style.root" :style="{ backgroundImage: `url(${ instance.backgroundImageUrl })` }"></div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { instance } from '@/instance.js';
import * as Misskey from 'misskey-js';
import { misskeyApi } from '@/scripts/misskey-api.js';
const meta = ref<Misskey.entities.MetaResponse>();
misskeyApi('meta', { detail: true }).then(gotMeta => {
meta.value = gotMeta;
});
</script> </script>
<style lang="scss" module> <style lang="scss" module>

View File

@ -4,19 +4,19 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<div v-if="meta" :class="$style.root"> <div v-if="instance" :class="$style.root">
<div :class="[$style.main, $style.panel]"> <div :class="[$style.main, $style.panel]">
<img :src="instance.iconUrl || '/favicon.ico'" alt="" :class="$style.mainIcon"/> <img :src="instance.iconUrl || '/favicon.ico'" alt="" :class="$style.mainIcon"/>
<button class="_button _acrylic" :class="$style.mainMenu" @click="showMenu"><i class="ti ti-dots"></i></button> <button class="_button _acrylic" :class="$style.mainMenu" @click="showMenu"><i class="ti ti-dots"></i></button>
<div :class="$style.mainFg"> <div :class="$style.mainFg">
<h1 :class="$style.mainTitle"> <h1 :class="$style.mainTitle">
<!-- 背景色によってはロゴが見えなくなるのでとりあえず無効に --> <!-- 背景色によってはロゴが見えなくなるのでとりあえず無効に -->
<!-- <img class="logo" v-if="meta.logoImageUrl" :src="meta.logoImageUrl"><span v-else class="text">{{ instanceName }}</span> --> <!-- <img class="logo" v-if="instance.logoImageUrl" :src="instance.logoImageUrl"><span v-else class="text">{{ instanceName }}</span> -->
<span>{{ instanceName }}</span> <span>{{ instanceName }}</span>
</h1> </h1>
<div :class="$style.mainAbout"> <div :class="$style.mainAbout">
<!-- eslint-disable-next-line vue/no-v-html --> <!-- eslint-disable-next-line vue/no-v-html -->
<div v-html="meta.description || i18n.ts.headlineMisskey"></div> <div v-html="instance.description || i18n.ts.headlineMisskey"></div>
</div> </div>
<div v-if="instance.disableRegistration" :class="$style.mainWarn"> <div v-if="instance.disableRegistration" :class="$style.mainWarn">
<MkInfo warn>{{ i18n.ts.invitationRequiredToRegister }}</MkInfo> <MkInfo warn>{{ i18n.ts.invitationRequiredToRegister }}</MkInfo>
@ -66,13 +66,8 @@ import { instance } from '@/instance.js';
import MkNumber from '@/components/MkNumber.vue'; import MkNumber from '@/components/MkNumber.vue';
import XActiveUsersChart from '@/components/MkVisitorDashboard.ActiveUsersChart.vue'; import XActiveUsersChart from '@/components/MkVisitorDashboard.ActiveUsersChart.vue';
const meta = ref<Misskey.entities.MetaResponse | null>(null);
const stats = ref<Misskey.entities.StatsResponse | null>(null); const stats = ref<Misskey.entities.StatsResponse | null>(null);
misskeyApi('meta', { detail: true }).then(_meta => {
meta.value = _meta;
});
misskeyApi('stats', {}).then((res) => { misskeyApi('stats', {}).then((res) => {
stats.value = res; stats.value = res;
}); });

View File

@ -28,7 +28,7 @@ if (providedAt > cachedAt) {
// TODO: instanceをリアクティブにするかは再考の余地あり // TODO: instanceをリアクティブにするかは再考の余地あり
export const instance: Misskey.entities.MetaResponse = reactive(cachedMeta ?? {}); export const instance: Misskey.entities.MetaDetailed = reactive(cachedMeta ?? {});
export const serverErrorImageUrl = computed(() => instance.serverErrorImageUrl ?? DEFAULT_SERVER_ERROR_IMAGE_URL); export const serverErrorImageUrl = computed(() => instance.serverErrorImageUrl ?? DEFAULT_SERVER_ERROR_IMAGE_URL);
@ -38,7 +38,7 @@ export const notFoundImageUrl = computed(() => instance.notFoundImageUrl ?? DEFA
export const isEnabledUrlPreview = computed(() => instance.enableUrlPreview ?? true); export const isEnabledUrlPreview = computed(() => instance.enableUrlPreview ?? true);
export async function fetchInstance(force = false): Promise<void> { export async function fetchInstance(force = false): Promise<Misskey.entities.MetaDetailed> {
if (!force) { if (!force) {
const cachedAt = miLocalStorage.getItem('instanceCachedAt') ? parseInt(miLocalStorage.getItem('instanceCachedAt')!) : 0; const cachedAt = miLocalStorage.getItem('instanceCachedAt') ? parseInt(miLocalStorage.getItem('instanceCachedAt')!) : 0;
@ -48,7 +48,7 @@ export async function fetchInstance(force = false): Promise<void> {
} }
const meta = await misskeyApi('meta', { const meta = await misskeyApi('meta', {
detail: false, detail: true,
}); });
for (const [k, v] of Object.entries(meta)) { for (const [k, v] of Object.entries(meta)) {
@ -57,4 +57,6 @@ export async function fetchInstance(force = false): Promise<void> {
miLocalStorage.setItem('instance', JSON.stringify(instance)); miLocalStorage.setItem('instance', JSON.stringify(instance));
miLocalStorage.setItem('instanceCachedAt', Date.now().toString()); miLocalStorage.setItem('instanceCachedAt', Date.now().toString());
return instance;
} }

View File

@ -42,11 +42,11 @@ import XTimeline from './welcome.timeline.vue';
import MarqueeText from '@/components/MkMarquee.vue'; import MarqueeText from '@/components/MkMarquee.vue';
import MkFeaturedPhotos from '@/components/MkFeaturedPhotos.vue'; import MkFeaturedPhotos from '@/components/MkFeaturedPhotos.vue';
import misskeysvg from '/client-assets/misskey.svg'; import misskeysvg from '/client-assets/misskey.svg';
import { misskeyApi, misskeyApiGet } from '@/scripts/misskey-api.js'; import { misskeyApiGet } from '@/scripts/misskey-api.js';
import MkVisitorDashboard from '@/components/MkVisitorDashboard.vue'; import MkVisitorDashboard from '@/components/MkVisitorDashboard.vue';
import { getProxiedImageUrl } from '@/scripts/media-proxy.js'; import { getProxiedImageUrl } from '@/scripts/media-proxy.js';
import { instance as meta } from '@/instance.js';
const meta = ref<Misskey.entities.MetaResponse>();
const instances = ref<Misskey.entities.FederationInstance[]>(); const instances = ref<Misskey.entities.FederationInstance[]>();
function getInstanceIcon(instance: Misskey.entities.FederationInstance): string { function getInstanceIcon(instance: Misskey.entities.FederationInstance): string {
@ -56,10 +56,6 @@ function getInstanceIcon(instance: Misskey.entities.FederationInstance): string
return getProxiedImageUrl(instance.iconUrl, 'preview'); return getProxiedImageUrl(instance.iconUrl, 'preview');
} }
misskeyApi('meta', { detail: true }).then(_meta => {
meta.value = _meta;
});
misskeyApiGet('federation/instances', { misskeyApiGet('federation/instances', {
sort: '+pubSub', sort: '+pubSub',
limit: 20, limit: 20,

View File

@ -4,8 +4,8 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<div v-if="meta"> <div v-if="instance">
<XSetup v-if="meta.requireSetup"/> <XSetup v-if="instance.requireSetup"/>
<XEntrance v-else/> <XEntrance v-else/>
</div> </div>
</template> </template>
@ -16,13 +16,13 @@ import * as Misskey from 'misskey-js';
import XSetup from './welcome.setup.vue'; import XSetup from './welcome.setup.vue';
import XEntrance from './welcome.entrance.a.vue'; import XEntrance from './welcome.entrance.a.vue';
import { instanceName } from '@/config.js'; import { instanceName } from '@/config.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { definePageMetadata } from '@/scripts/page-metadata.js'; import { definePageMetadata } from '@/scripts/page-metadata.js';
import { fetchInstance } from '@/instance.js';
const meta = ref<Misskey.entities.MetaResponse | null>(null); const instance = ref<Misskey.entities.MetaDetailed | null>(null);
misskeyApi('meta', { detail: true }).then(res => { fetchInstance(true).then((res) => {
meta.value = res; instance.value = res;
}); });
const headerActions = computed(() => []); const headerActions = computed(() => []);

View File

@ -70,11 +70,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, provide, ref, computed } from 'vue'; import { onMounted, provide, ref, computed } from 'vue';
import * as Misskey from 'misskey-js';
import XCommon from './_common_/common.vue'; import XCommon from './_common_/common.vue';
import { instanceName } from '@/config.js'; import { instanceName } from '@/config.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { instance } from '@/instance.js'; import { instance } from '@/instance.js';
import XSigninDialog from '@/components/MkSigninDialog.vue'; import XSigninDialog from '@/components/MkSigninDialog.vue';
import XSignupDialog from '@/components/MkSignupDialog.vue'; import XSignupDialog from '@/components/MkSignupDialog.vue';
@ -114,7 +112,6 @@ const isTimelineAvailable = ref(instance.policies?.ltlAvailable || instance.poli
const showMenu = ref(false); const showMenu = ref(false);
const isDesktop = ref(window.innerWidth >= DESKTOP_THRESHOLD); const isDesktop = ref(window.innerWidth >= DESKTOP_THRESHOLD);
const narrow = ref(window.innerWidth < 1280); const narrow = ref(window.innerWidth < 1280);
const meta = ref<Misskey.entities.MetaResponse>();
const keymap = computed(() => { const keymap = computed(() => {
return { return {
@ -128,10 +125,6 @@ const keymap = computed(() => {
}; };
}); });
misskeyApi('meta', { detail: true }).then(res => {
meta.value = res;
});
function signin() { function signin() {
os.popup(XSigninDialog, { os.popup(XSigninDialog, {
autoSet: true, autoSet: true,