Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: stats apiの重い処理をスキップできるように #15062

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Fix: 画面サイズが変わった際にナビゲーションバーが自動で折りたたまれない問題を修正

### Server
- Enhance: `/stats` APIの重い処理をスキップできるようにするオプションを追加
- 処理がスキップされた部分の値は`0`となります
- Fix: ユーザーのプロフィール画面をアドレス入力などで直接表示した際に概要タブの描画に失敗する問題の修正( #15032 )


Expand Down
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5222,6 +5222,10 @@ export interface Locale extends ILocale {
* 注意事項を理解した上でオンにします。
*/
"acknowledgeNotesAndEnable": string;
/**
* 拡張されたサーバー統計APIを利用する
*/
"enableEnhancedServerStats": string;
"_accountSettings": {
/**
* コンテンツの表示にログインを必須にする
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ lockdown: "ロックダウン"
pleaseSelectAccount: "アカウントを選択してください"
availableRoles: "利用可能なロール"
acknowledgeNotesAndEnable: "注意事項を理解した上でオンにします。"
enableEnhancedServerStats: "拡張されたサーバー統計APIを利用する"

_accountSettings:
requireSigninToViewContents: "コンテンツの表示にログインを必須にする"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"`);
}
}
5 changes: 5 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ export class MiMeta {
})
public enableIdenticonGeneration: boolean;

@Column('boolean', {
default: true,
})
public enableEnhancedServerStats: boolean;

@Column('jsonb', {
default: { },
})
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -641,6 +645,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances,
enableStatsForFederatedInstances: instance.enableStatsForFederatedInstances,
enableServerMachineStats: instance.enableServerMachineStats,
enableEnhancedServerStats: instance.enableEnhancedServerStats,
enableIdenticonGeneration: instance.enableIdenticonGeneration,
bannedEmailDomains: instance.bannedEmailDomains,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
Expand Down Expand Up @@ -587,6 +588,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.enableServerMachineStats = ps.enableServerMachineStats;
}

if (ps.enableEnhancedServerStats !== undefined) {
set.enableEnhancedServerStats = ps.enableEnhancedServerStats;
}

if (ps.enableIdenticonGeneration !== undefined) {
set.enableIdenticonGeneration = ps.enableIdenticonGeneration;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/server/api/endpoints/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -60,6 +60,9 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.meta)
private instanceMeta: MiMeta,

@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,

Expand All @@ -83,7 +86,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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 }),
]);
Expand Down
16 changes: 16 additions & 0 deletions packages/frontend/src/pages/admin/performance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch>
</div>

<div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableEnhancedServerStats" @change="onChange_enableEnhancedServerStats">
<template #label>{{ i18n.ts.enableEnhancedServerStats }}</template>
<template #caption>{{ i18n.ts.turnOffToImprovePerformance }}</template>
</MkSwitch>
</div>

<div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableIdenticonGeneration" @change="onChange_enableIdenticonGeneration">
<template #label>{{ i18n.ts.enableIdenticonGeneration }}</template>
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5179,6 +5179,7 @@ export type operations = {
enableChartsForFederatedInstances: boolean;
enableStatsForFederatedInstances: boolean;
enableServerMachineStats: boolean;
enableEnhancedServerStats: boolean;
enableIdenticonGeneration: boolean;
manifestJsonOverride: string;
policies: Record<string, never>;
Expand Down Expand Up @@ -9575,6 +9576,7 @@ export type operations = {
enableChartsForFederatedInstances?: boolean;
enableStatsForFederatedInstances?: boolean;
enableServerMachineStats?: boolean;
enableEnhancedServerStats?: boolean;
enableIdenticonGeneration?: boolean;
serverRules?: string[];
bannedEmailDomains?: string[];
Expand Down
Loading