From 8fc916ec50d2e08aa4e6b35da48b097090a32bd1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 18 Jun 2019 16:49:58 +0900 Subject: [PATCH] Resolve #5063 --- locales/ja-JP.yml | 4 ++ src/client/app/admin/views/db.vue | 39 +++++++++++++++++++ src/client/app/admin/views/index.vue | 31 ++++++++------- .../api/endpoints/admin/get-table-stats.ts | 37 ++++++++++++++++++ 4 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 src/client/app/admin/views/db.vue create mode 100644 src/server/api/endpoints/admin/get-table-stats.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 7053360a1..d9223b1c4 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1226,8 +1226,12 @@ admin/views/index.vue: abuse: "スパム報告" queue: "ジョブキュー" logs: "ログ" + db: "データベース" back-to-misskey: "Misskeyに戻る" +admin/views/db.vue: + tables: "テーブル" + admin/views/dashboard.vue: dashboard: "ダッシュボード" accounts: "アカウント" diff --git a/src/client/app/admin/views/db.vue b/src/client/app/admin/views/db.vue new file mode 100644 index 000000000..27bb81039 --- /dev/null +++ b/src/client/app/admin/views/db.vue @@ -0,0 +1,39 @@ + + + diff --git a/src/client/app/admin/views/index.vue b/src/client/app/admin/views/index.vue index 43e47038f..8a13fe1bf 100644 --- a/src/client/app/admin/views/index.vue +++ b/src/client/app/admin/views/index.vue @@ -22,6 +22,7 @@
  • {{ $t('instance') }}
  • {{ $t('queue') }}
  • {{ $t('logs') }}
  • +
  • {{ $t('db') }}
  • {{ $t('moderators') }}
  • {{ $t('users') }}
  • {{ $t('@.drive') }}
  • @@ -43,6 +44,7 @@
    +
    @@ -59,19 +61,20 @@ import Vue from 'vue'; import i18n from '../../i18n'; import { version } from '../../config'; -import XDashboard from "./dashboard.vue"; -import XInstance from "./instance.vue"; -import XQueue from "./queue.vue"; -import XLogs from "./logs.vue"; -import XModerators from "./moderators.vue"; -import XEmoji from "./emoji.vue"; -import XAnnouncements from "./announcements.vue"; -import XUsers from "./users.vue"; -import XDrive from "./drive.vue"; -import XAbuse from "./abuse.vue"; -import XFederation from "./federation.vue"; +import XDashboard from './dashboard.vue'; +import XInstance from './instance.vue'; +import XQueue from './queue.vue'; +import XLogs from './logs.vue'; +import XDb from './db.vue'; +import XModerators from './moderators.vue'; +import XEmoji from './emoji.vue'; +import XAnnouncements from './announcements.vue'; +import XUsers from './users.vue'; +import XDrive from './drive.vue'; +import XAbuse from './abuse.vue'; +import XFederation from './federation.vue'; -import { faHeadset, faArrowLeft, faGlobe, faExclamationCircle, faTasks, faStream } from '@fortawesome/free-solid-svg-icons'; +import { faHeadset, faArrowLeft, faGlobe, faExclamationCircle, faTasks, faStream, faDatabase } from '@fortawesome/free-solid-svg-icons'; import { faGrin } from '@fortawesome/free-regular-svg-icons'; // Detect the user agent @@ -85,6 +88,7 @@ export default Vue.extend({ XInstance, XQueue, XLogs, + XDb, XModerators, XEmoji, XAnnouncements, @@ -108,7 +112,8 @@ export default Vue.extend({ faGlobe, faExclamationCircle, faTasks, - faStream + faStream, + faDatabase, }; }, methods: { diff --git a/src/server/api/endpoints/admin/get-table-stats.ts b/src/server/api/endpoints/admin/get-table-stats.ts new file mode 100644 index 000000000..1abea1849 --- /dev/null +++ b/src/server/api/endpoints/admin/get-table-stats.ts @@ -0,0 +1,37 @@ +import define from '../../define'; +import { getConnection } from 'typeorm'; + +export const meta = { + requireCredential: false, + + desc: { + 'en-US': 'Get table stats' + }, + + tags: ['meta'], + + params: { + }, +}; + +export default define(meta, async () => { + const sizes = await + getConnection().query(` + SELECT relname AS "table", reltuples as "count", pg_total_relation_size(C.oid) AS "size" + FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) + WHERE nspname NOT IN ('pg_catalog', 'information_schema') + AND C.relkind <> 'i' + AND nspname !~ '^pg_toast';`) + .then(recs => { + const res = {} as Record; + for (const rec of recs) { + res[rec.table] = { + count: parseInt(rec.count, 10), + size: parseInt(rec.size, 10), + }; + } + return res; + }); + + return sizes; +});