Skip to content

Commit

Permalink
CDNキャッシュのオン・オフを切り替えられるように
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Dec 28, 2024
1 parent 5ad0fe7 commit 677e980
Show file tree
Hide file tree
Showing 12 changed files with 1,418 additions and 1 deletion.
8 changes: 8 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5222,6 +5222,14 @@ export interface Locale extends ILocale {
* 注意事項を理解した上でオンにします。
*/
"acknowledgeNotesAndEnable": string;
/**
* リアルタイム更新時のノート取得にCDNキャッシュを併用する
*/
"enableStreamNotesCdnCache": string;
/**
* サーバーでCDNを使用している場合は、この設定をオンにしたうえでCDNの設定を適切に調整するとサーバーへの負荷を軽減できます(上級者向け)。WebSocket通信ではリアルタイム性のある情報のみを送信し、残りの情報はCDNキャッシュから取得して突合します。このため、クライアント側の負荷やデータ通信量に影響が出る可能性があります。
*/
"enableStreamNotesCdnCacheDescription": string;
"_accountSettings": {
/**
* コンテンツの表示にログインを必須にする
Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,8 @@ lockdown: "ロックダウン"
pleaseSelectAccount: "アカウントを選択してください"
availableRoles: "利用可能なロール"
acknowledgeNotesAndEnable: "注意事項を理解した上でオンにします。"
enableStreamNotesCdnCache: "リアルタイム更新時のノート取得にCDNキャッシュを併用する"
enableStreamNotesCdnCacheDescription: "サーバーでCDNを使用している場合は、この設定をオンにしたうえでCDNの設定を適切に調整するとサーバーへの負荷を軽減できます(上級者向け)。WebSocket通信ではリアルタイム性のある情報のみを送信し、残りの情報はCDNキャッシュから取得して突合します。このため、クライアント側の負荷やデータ通信量に影響が出る可能性があります。"

_accountSettings:
requireSigninToViewContents: "コンテンツの表示にログインを必須にする"
Expand Down
16 changes: 16 additions & 0 deletions packages/backend/migration/1735377503979-StreamNotesCdnCache.js
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 StreamNotesCdnCache1735377503979 {
name = 'StreamNotesCdnCache1735377503979'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "enableStreamNotesCdnCache" boolean NOT NULL DEFAULT false`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableStreamNotesCdnCache"`);
}
}
5 changes: 5 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ export class MiMeta {
})
public enableReactionsBuffering: boolean;

@Column('boolean', {
default: false,
})
public enableStreamNotesCdnCache: boolean;

@Column('integer', {
default: 0,
})
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export const packedMetaLiteSchema = {
type: 'boolean',
optional: false, nullable: false,
},
enableStreamNotesCdnCache: {
type: 'boolean',
optional: false, nullable: false,
},
backgroundImageUrl: {
type: 'string',
optional: false, nullable: true,
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 @@ -396,6 +396,10 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
enableStreamNotesCdnCache: {
type: 'boolean',
optional: false, nullable: false,
},
notesPerOneAd: {
type: 'number',
optional: false, nullable: false,
Expand Down Expand Up @@ -652,6 +656,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax,
perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax,
enableReactionsBuffering: instance.enableReactionsBuffering,
enableStreamNotesCdnCache: instance.enableStreamNotesCdnCache,
notesPerOneAd: instance.notesPerOneAd,
summalyProxy: instance.urlPreviewSummaryProxyUrl,
urlPreviewEnabled: instance.urlPreviewEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const paramDef = {
perUserHomeTimelineCacheMax: { type: 'integer' },
perUserListTimelineCacheMax: { type: 'integer' },
enableReactionsBuffering: { type: 'boolean' },
enableStreamNotesCdnCache: { type: 'boolean' },
notesPerOneAd: { type: 'integer' },
silencedHosts: {
type: 'array',
Expand Down Expand Up @@ -631,6 +632,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.enableReactionsBuffering = ps.enableReactionsBuffering;
}

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

if (ps.notesPerOneAd !== undefined) {
set.notesPerOneAd = ps.notesPerOneAd;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ export class ClientServerService {
});

fastify.get<{ Params: { note: string; } }>('/notes/:note.json', async (request, reply) => {
// 内部用途なのでCORSを無効化
reply.removeHeader('Access-Control-Allow-Origin');

// this.meta.enableStreamNotesCdnCacheにかかわらずレスポンスは返す
// (このプロパティを見ずにminimizeでChannelに繋いだ場合用)

const note = await this.notesRepository.findOneBy({
id: request.params.note,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function prepend(data: Misskey.entities.Note | Misskey.entities.StreamNote
let connection: Misskey.ChannelConnection | null = null;
let connection2: Misskey.ChannelConnection | null = null;
let paginationQuery: Paging | null = null;
const minimize = !iAmModerator;
const minimize = !iAmModerator && instance.enableStreamNotesCdnCache;

const stream = useStream();

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 @@ -43,6 +43,13 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch>
</div>

<div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableStreamNotesCdnCache" @change="onChange_enableStreamNotesCdnCache">
<template #label>{{ i18n.ts.enableStreamNotesCdnCache }}<span class="_beta">{{ i18n.ts.beta }}</span></template>
<template #caption>{{ i18n.ts.enableStreamNotesCdnCacheDescription }}</template>
</MkSwitch>
</div>

<MkFolder :defaultOpen="true">
<template #icon><i class="ti ti-bolt"></i></template>
<template #label>Misskey® Fan-out Timeline Technology™ (FTT)</template>
Expand Down Expand Up @@ -129,6 +136,7 @@ const enableIdenticonGeneration = ref(meta.enableIdenticonGeneration);
const enableChartsForRemoteUser = ref(meta.enableChartsForRemoteUser);
const enableStatsForFederatedInstances = ref(meta.enableStatsForFederatedInstances);
const enableChartsForFederatedInstances = ref(meta.enableChartsForFederatedInstances);
const enableStreamNotesCdnCache = ref(meta.enableStreamNotesCdnCache);

function onChange_enableServerMachineStats(value: boolean) {
os.apiWithDialog('admin/update-meta', {
Expand Down Expand Up @@ -170,6 +178,14 @@ function onChange_enableChartsForFederatedInstances(value: boolean) {
});
}

function onChange_enableStreamNotesCdnCache(value: boolean) {
os.apiWithDialog('admin/update-meta', {
enableStreamNotesCdnCache: value,
}).then(() => {
fetchInstance(true);
});
}

const fttForm = useForm({
enableFanoutTimeline: meta.enableFanoutTimeline,
enableFanoutTimelineDbFallback: meta.enableFanoutTimelineDbFallback,
Expand Down
Loading

0 comments on commit 677e980

Please sign in to comment.