From c0efad6ee3fb4ef75e3d52ebf0d76cd6045e520f Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:57:40 +0900 Subject: [PATCH 1/2] =?UTF-8?q?enhance:=20stats=20api=E3=81=AE=E9=87=8D?= =?UTF-8?q?=E3=81=84=E5=87=A6=E7=90=86=E3=82=92=E3=82=B9=E3=82=AD=E3=83=83?= =?UTF-8?q?=E3=83=97=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/index.d.ts | 4 ++++ locales/ja-JP.yml | 1 + .../1732635823870-EnableEnhancedServerStats.js | 16 ++++++++++++++++ packages/backend/src/models/Meta.ts | 5 +++++ .../src/server/api/endpoints/admin/meta.ts | 5 +++++ .../server/api/endpoints/admin/update-meta.ts | 5 +++++ .../backend/src/server/api/endpoints/stats.ts | 7 +++++-- .../frontend/src/pages/admin/performance.vue | 16 ++++++++++++++++ packages/misskey-js/src/autogen/types.ts | 2 ++ 9 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 packages/backend/migration/1732635823870-EnableEnhancedServerStats.js diff --git a/locales/index.d.ts b/locales/index.d.ts index 0ae188f1f7..e6cff7f09b 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -5222,6 +5222,10 @@ export interface Locale extends ILocale { * 注意事項を理解した上でオンにします。 */ "acknowledgeNotesAndEnable": string; + /** + * 拡張されたサーバー統計APIを利用する + */ + "enableEnhancedServerStats": string; "_accountSettings": { /** * コンテンツの表示にログインを必須にする diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 1b59708d85..39109ab617 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1301,6 +1301,7 @@ lockdown: "ロックダウン" pleaseSelectAccount: "アカウントを選択してください" availableRoles: "利用可能なロール" acknowledgeNotesAndEnable: "注意事項を理解した上でオンにします。" +enableEnhancedServerStats: "拡張されたサーバー統計APIを利用する" _accountSettings: requireSigninToViewContents: "コンテンツの表示にログインを必須にする" diff --git a/packages/backend/migration/1732635823870-EnableEnhancedServerStats.js b/packages/backend/migration/1732635823870-EnableEnhancedServerStats.js new file mode 100644 index 0000000000..51e692c487 --- /dev/null +++ b/packages/backend/migration/1732635823870-EnableEnhancedServerStats.js @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export class EnableEnhancedServerStats1732635823870 { + name = 'EnableEnhancedServerStats1732635823870' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "enableEnhancedServerStats" boolean NOT NULL DEFAULT true`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableEnhancedServerStats"`); + } +} diff --git a/packages/backend/src/models/Meta.ts b/packages/backend/src/models/Meta.ts index ad5e31ad6f..97875ade07 100644 --- a/packages/backend/src/models/Meta.ts +++ b/packages/backend/src/models/Meta.ts @@ -544,6 +544,11 @@ export class MiMeta { }) public enableIdenticonGeneration: boolean; + @Column('boolean', { + default: true, + }) + public enableEnhancedServerStats: boolean; + @Column('jsonb', { default: { }, }) diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index 64e3cc33bd..933deeac62 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -356,6 +356,10 @@ export const meta = { type: 'boolean', optional: false, nullable: false, }, + enableEnhancedServerStats: { + type: 'boolean', + optional: false, nullable: false, + }, enableIdenticonGeneration: { type: 'boolean', optional: false, nullable: false, @@ -641,6 +645,7 @@ export default class extends Endpoint { // eslint- enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances, enableStatsForFederatedInstances: instance.enableStatsForFederatedInstances, enableServerMachineStats: instance.enableServerMachineStats, + enableEnhancedServerStats: instance.enableEnhancedServerStats, enableIdenticonGeneration: instance.enableIdenticonGeneration, bannedEmailDomains: instance.bannedEmailDomains, policies: { ...DEFAULT_POLICIES, ...instance.policies }, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 38ef0d1de8..350805e449 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -138,6 +138,7 @@ export const paramDef = { enableChartsForFederatedInstances: { type: 'boolean' }, enableStatsForFederatedInstances: { type: 'boolean' }, enableServerMachineStats: { type: 'boolean' }, + enableEnhancedServerStats: { type: 'boolean' }, enableIdenticonGeneration: { type: 'boolean' }, serverRules: { type: 'array', items: { type: 'string' } }, bannedEmailDomains: { type: 'array', items: { type: 'string' } }, @@ -587,6 +588,10 @@ export default class extends Endpoint { // eslint- set.enableServerMachineStats = ps.enableServerMachineStats; } + if (ps.enableEnhancedServerStats !== undefined) { + set.enableEnhancedServerStats = ps.enableEnhancedServerStats; + } + if (ps.enableIdenticonGeneration !== undefined) { set.enableIdenticonGeneration = ps.enableIdenticonGeneration; } diff --git a/packages/backend/src/server/api/endpoints/stats.ts b/packages/backend/src/server/api/endpoints/stats.ts index 1e6983177f..b3b6e7daaf 100644 --- a/packages/backend/src/server/api/endpoints/stats.ts +++ b/packages/backend/src/server/api/endpoints/stats.ts @@ -4,7 +4,7 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import type { InstancesRepository, NoteReactionsRepository } from '@/models/_.js'; +import type { MiMeta, InstancesRepository, NoteReactionsRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import NotesChart from '@/core/chart/charts/notes.js'; @@ -60,6 +60,9 @@ export const paramDef = { @Injectable() export default class extends Endpoint { // eslint-disable-line import/no-default-export constructor( + @Inject(DI.meta) + private instanceMeta: MiMeta, + @Inject(DI.instancesRepository) private instancesRepository: InstancesRepository, @@ -83,7 +86,7 @@ export default class extends Endpoint { // eslint- //originalReactionsCount, instances, ] = await Promise.all([ - this.noteReactionsRepository.count({ cache: 3600000 }), // 1 hour + this.instanceMeta.enableEnhancedServerStats ? this.noteReactionsRepository.count({ cache: 3600000 }) : Promise.resolve(0), // 1 hour //this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }), this.instancesRepository.count({ cache: 3600000 }), ]); diff --git a/packages/frontend/src/pages/admin/performance.vue b/packages/frontend/src/pages/admin/performance.vue index 12338f0bf9..f9bd003237 100644 --- a/packages/frontend/src/pages/admin/performance.vue +++ b/packages/frontend/src/pages/admin/performance.vue @@ -15,6 +15,13 @@ SPDX-License-Identifier: AGPL-3.0-only +
+ + + + +
+
@@ -125,6 +132,7 @@ import MkFormFooter from '@/components/MkFormFooter.vue'; const meta = await misskeyApi('admin/meta'); const enableServerMachineStats = ref(meta.enableServerMachineStats); +const enableEnhancedServerStats = ref(meta.enableEnhancedServerStats); const enableIdenticonGeneration = ref(meta.enableIdenticonGeneration); const enableChartsForRemoteUser = ref(meta.enableChartsForRemoteUser); const enableStatsForFederatedInstances = ref(meta.enableStatsForFederatedInstances); @@ -138,6 +146,14 @@ function onChange_enableServerMachineStats(value: boolean) { }); } +function onChange_enableEnhancedServerStats(value: boolean) { + os.apiWithDialog('admin/update-meta', { + enableEnhancedServerStats: value, + }).then(() => { + fetchInstance(true); + }); +} + function onChange_enableIdenticonGeneration(value: boolean) { os.apiWithDialog('admin/update-meta', { enableIdenticonGeneration: value, diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 280abba727..a2ad1e6c9e 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -5179,6 +5179,7 @@ export type operations = { enableChartsForFederatedInstances: boolean; enableStatsForFederatedInstances: boolean; enableServerMachineStats: boolean; + enableEnhancedServerStats: boolean; enableIdenticonGeneration: boolean; manifestJsonOverride: string; policies: Record; @@ -9575,6 +9576,7 @@ export type operations = { enableChartsForFederatedInstances?: boolean; enableStatsForFederatedInstances?: boolean; enableServerMachineStats?: boolean; + enableEnhancedServerStats?: boolean; enableIdenticonGeneration?: boolean; serverRules?: string[]; bannedEmailDomains?: string[]; From 43ac9fc985b74da83049cd057dd4a22d56e76ca9 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:59:01 +0900 Subject: [PATCH 2/2] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7896a42883..9c3018c00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Fix: 画面サイズが変わった際にナビゲーションバーが自動で折りたたまれない問題を修正 ### Server +- Enhance: `/stats` APIの重い処理をスキップできるようにするオプションを追加 + - 処理がスキップされた部分の値は`0`となります - Fix: ユーザーのプロフィール画面をアドレス入力などで直接表示した際に概要タブの描画に失敗する問題の修正( #15032 )