Skip to content

Commit e5d710c

Browse files
committed
perf: add instance DB size to index sidebar. gh-180
1 parent 4d12dce commit e5d710c

File tree

7 files changed

+36
-12
lines changed

7 files changed

+36
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"dayjs": "^1.11.13",
3838
"echarts": "^5.5.1",
3939
"echarts-for-react": "^3.0.2",
40+
"filesize": "^10.1.6",
4041
"framer-motion": "^11.11.7",
4142
"fuse.js": "^7.0.0",
4243
"i18next": "^23.15.2",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/instance.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"version": {
88
"label": "Meilisearch Version"
99
},
10-
"db_size": "DB Size",
10+
"db_size": "Instance DB Size",
1111
"meili_version": "Meili Version",
1212
"connection_failed": "Connection fail, go check your config! 🤥",
1313
"create_index": {

src/locales/zh/instance.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"version": {
88
"label": "Meilisearch 版本"
99
},
10-
"db_size": "数据库大小",
10+
"db_size": "实例数据库大小",
1111
"meili_version": "Meili 版本",
1212
"connection_failed": "连接失败, 去检查你的配置! 🤥",
1313
"create_index": {

src/routes/ins/$insID/_layout/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { useMeiliClient } from '@/hooks/useMeiliClient';
66
import { useInstanceStats } from '@/hooks/useInstanceStats';
77
import { useMemo } from 'react';
88
import { Copyable } from '@/components/Copyable';
9-
import _ from 'lodash';
109
import { useInstanceHealth } from '@/hooks/useInstanceHealth';
1110
import { IndexList } from '@/components/IndexList';
1211
import { TitleWithUnderline } from '@/components/title';
@@ -18,6 +17,7 @@ import { LoaderPage } from '@/components/loader';
1817
import { isSingletonMode } from '@/utils/conn';
1918
import { Footer } from '@/components/Footer';
2019
import { TimeAgo } from '@/components/timeago';
20+
import { filesize } from 'filesize';
2121

2222
function InsDash() {
2323
const { t } = useTranslation('instance');
@@ -40,7 +40,7 @@ function InsDash() {
4040
key: t('db_size'),
4141
value: (
4242
<Skeleton placeholder={<Skeleton.Title />} active loading={!stats?.databaseSize}>
43-
{`${_.ceil((stats?.databaseSize ?? 0) / 1048576, 2)} MB`}
43+
{filesize(stats?.databaseSize ?? 0)}
4444
</Skeleton>
4545
),
4646
},

src/routes/ins/$insID/_layout/index/$indexUID/_layout.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { TitleWithUnderline } from '@/components/title';
99
import { Button } from '@nextui-org/react';
1010
import { IndexPrimaryKey } from '@/components/indexPrimaryKey';
1111
import { TimeAgo } from '@/components/timeago';
12+
import { useInstanceStats } from '@/hooks/useInstanceStats';
13+
import { Skeleton } from '@douyinfe/semi-ui';
14+
import { filesize } from 'filesize';
1215

1316
const InfoRow = ({ value, label }: { label: string; value: ReactNode }) => {
1417
return (
@@ -23,6 +26,7 @@ function IndexDash() {
2326
const { t } = useTranslation('index');
2427
const client = useMeiliClient();
2528
const currentIndex = useCurrentIndex(client);
29+
const stats = useInstanceStats(client);
2630

2731
console.debug('index dash page building', currentIndex);
2832

@@ -45,6 +49,14 @@ function IndexDash() {
4549
}
4650
/>
4751
)}
52+
<InfoRow
53+
label={t('instance:db_size')}
54+
value={
55+
<Skeleton placeholder={<Skeleton.Title />} active loading={!stats?.databaseSize}>
56+
{filesize(stats?.databaseSize ?? 0)}
57+
</Skeleton>
58+
}
59+
/>
4860
<div className="flex flex-col gap-3 items-stretch">
4961
<Link to="" from="/ins/$insID/index/$indexUID">
5062
<Button fullWidth variant="light" size="sm">
@@ -93,7 +105,7 @@ function IndexDash() {
93105
</div>
94106
</div>
95107
);
96-
}, [currentIndex.index, t]);
108+
}, [currentIndex.index, stats?.databaseSize, t]);
97109
}
98110

99111
export const Route = createFileRoute('/ins/$insID/_layout/index/$indexUID/_layout')({

src/routes/ins/$insID/_layout/tasks.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import { useTranslation } from 'react-i18next';
1616
import ReactJson from 'react-json-view';
1717
import { z } from 'zod';
1818

19-
const searchSchema = z.object({
20-
indexUids: z.string().array().optional(),
21-
limit: z.number().positive().optional(),
22-
from: z.number().nonnegative().optional(),
23-
statuses: z.string().array().optional(),
24-
types: z.string().array().optional(),
25-
});
19+
const searchSchema = z
20+
.object({
21+
indexUids: z.string().array().optional(),
22+
limit: z.number().positive().optional(),
23+
from: z.number().nonnegative().optional(),
24+
statuses: z.string().array().optional(),
25+
types: z.string().array().optional(),
26+
})
27+
.optional();
2628

2729
type State = Pick<TasksQuery, 'indexUids' | 'statuses' | 'types'> & Required<Pick<TasksQuery, 'limit' | 'from'>>;
2830

0 commit comments

Comments
 (0)