From f17e229c1e390eb98f167c918dde87dbbfcaacf2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 3 Jul 2019 03:58:45 +0900 Subject: [PATCH] Resolve #5072 --- locales/ja-JP.yml | 3 +++ src/client/app/admin/views/db.vue | 26 +++++++++++++++++-- src/server/api/endpoints/admin/vacuum.ts | 33 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/server/api/endpoints/admin/vacuum.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index a19209357..9d104456f 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1235,6 +1235,9 @@ admin/views/index.vue: admin/views/db.vue: tables: "テーブル" + vacuum: "バキューム" + vacuum-info: "データベースの掃除を行います。データはそのままで、ディスク使用量を減らします。通常この操作は自動で定期的に行われます。" + vacuum-exclamation: "バキュームを行うと、しばらくの間データベースの負荷が高くなり、ユーザーの操作を受け付けなくなる場合があります。" admin/views/dashboard.vue: dashboard: "ダッシュボード" diff --git a/src/client/app/admin/views/db.vue b/src/client/app/admin/views/db.vue index 7818546e7..9f87a749b 100644 --- a/src/client/app/admin/views/db.vue +++ b/src/client/app/admin/views/db.vue @@ -5,6 +5,14 @@
{{ table }} {{ tables[table].count | number }} {{ tables[table].size | bytes }}
+
+
{{ $t('vacuum') }}
+ {{ $t('vacuum-info') }} + FULL + ANALYZE + {{ $t('vacuum') }} + {{ $t('vacuum-exclamation') }} +
@@ -12,7 +20,7 @@ diff --git a/src/server/api/endpoints/admin/vacuum.ts b/src/server/api/endpoints/admin/vacuum.ts new file mode 100644 index 000000000..699070628 --- /dev/null +++ b/src/server/api/endpoints/admin/vacuum.ts @@ -0,0 +1,33 @@ +import $ from 'cafy'; +import define from '../../define'; +import { getConnection } from 'typeorm'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + params: { + full: { + validator: $.bool, + }, + analyze: { + validator: $.bool, + }, + } +}; + +export default define(meta, async (ps) => { + const params: string[] = []; + + if (ps.full) { + params.push('FULL'); + } + + if (ps.analyze) { + params.push('ANALYZE'); + } + + getConnection().query('VACUUM ' + params.join(' ')); +});