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>
<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>
<script lang="ts" setup>
import { ref } from 'vue';
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;
});
import { instance } from '@/instance.js';
</script>
<style lang="scss" module>

View file

@ -4,19 +4,19 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div v-if="meta" :class="$style.root">
<div v-if="instance" :class="$style.root">
<div :class="[$style.main, $style.panel]">
<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>
<div :class="$style.mainFg">
<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>
</h1>
<div :class="$style.mainAbout">
<!-- 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 v-if="instance.disableRegistration" :class="$style.mainWarn">
<MkInfo warn>{{ i18n.ts.invitationRequiredToRegister }}</MkInfo>
@ -66,13 +66,8 @@ import { instance } from '@/instance.js';
import MkNumber from '@/components/MkNumber.vue';
import XActiveUsersChart from '@/components/MkVisitorDashboard.ActiveUsersChart.vue';
const meta = ref<Misskey.entities.MetaResponse | null>(null);
const stats = ref<Misskey.entities.StatsResponse | null>(null);
misskeyApi('meta', { detail: true }).then(_meta => {
meta.value = _meta;
});
misskeyApi('stats', {}).then((res) => {
stats.value = res;
});

View file

@ -28,7 +28,7 @@ if (providedAt > cachedAt) {
// 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);
@ -38,7 +38,7 @@ export const notFoundImageUrl = computed(() => instance.notFoundImageUrl ?? DEFA
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) {
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', {
detail: false,
detail: true,
});
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('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 MkFeaturedPhotos from '@/components/MkFeaturedPhotos.vue';
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 { 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[]>();
function getInstanceIcon(instance: Misskey.entities.FederationInstance): string {
@ -56,10 +56,6 @@ function getInstanceIcon(instance: Misskey.entities.FederationInstance): string
return getProxiedImageUrl(instance.iconUrl, 'preview');
}
misskeyApi('meta', { detail: true }).then(_meta => {
meta.value = _meta;
});
misskeyApiGet('federation/instances', {
sort: '+pubSub',
limit: 20,

View file

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

View file

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