Skip to content

Commit 62395f8

Browse files
committed
perf: admin
1 parent 39c59ef commit 62395f8

File tree

4 files changed

+107
-13
lines changed

4 files changed

+107
-13
lines changed

.github/workflows/admin-image.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build fastgpt-admin images and copy image to docker hub
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- 'main'
7+
tags:
8+
- 'v*.*.*'
9+
jobs:
10+
build-images:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 1
17+
- name: Install Dependencies
18+
run: |
19+
sudo apt update && sudo apt install -y nodejs npm
20+
- name: Set up QEMU (optional)
21+
uses: docker/setup-qemu-action@v2
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v2
24+
with:
25+
driver-opts: network=host
26+
- name: Login to GitHub Container Registry
27+
uses: docker/login-action@v2
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.repository_owner }}
31+
password: ${{ secrets.GH_PAT }}
32+
- name: Set DOCKER_REPO_TAGGED based on branch or tag
33+
run: |
34+
if [[ "${{ github.ref_name }}" == "main" ]]; then
35+
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-admin:latest" >> $GITHUB_ENV
36+
else
37+
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-admin:${{ github.ref_name }}" >> $GITHUB_ENV
38+
fi
39+
40+
- name: Build and publish image for main branch or tag push event
41+
env:
42+
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
43+
run: |
44+
cd client && \
45+
docker buildx build \
46+
--platform linux/amd64,linux/arm64 \
47+
--label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \
48+
--label "org.opencontainers.image.description=fastgpt-admin image" \
49+
--label "org.opencontainers.image.licenses=MIT" \
50+
--push \
51+
-t ${DOCKER_REPO_TAGGED} \
52+
-f Dockerfile \
53+
.
54+
push-to-docker-hub:
55+
needs: build-images
56+
runs-on: ubuntu-20.04
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@v3
60+
- name: Login to Docker Hub
61+
uses: docker/login-action@v2
62+
with:
63+
username: ${{ secrets.DOCKER_HUB_NAME }}
64+
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
65+
- name: Set DOCKER_REPO_TAGGED based on branch or tag
66+
run: |
67+
if [[ "${{ github.ref_name }}" == "main" ]]; then
68+
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
69+
else
70+
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
71+
fi
72+
- name: Pull image from GitHub Container Registry
73+
run: docker pull ghcr.io/${{ github.repository_owner }}/fastgpt-admin:${{env.IMAGE_TAG}}
74+
- name: Tag image with Docker Hub repository name and version tag
75+
run: docker tag ghcr.io/${{ github.repository_owner }}/fastgpt-admin:${{env.IMAGE_TAG}} ${{ secrets.DOCKER_IMAGE_NAME }}:${{env.IMAGE_TAG}}
76+
- name: Push image to Docker Hub
77+
run: docker push ${{ secrets.DOCKER_IMAGE_NAME }}:${{env.IMAGE_TAG}}

.github/workflows/image.yml renamed to .github/workflows/fastgpt-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build images and copy image to docker
1+
name: Build fastgpt images and copy image to docker hub
22
on:
33
workflow_dispatch:
44
push:

admin/service/route/user.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,21 @@ export const useUserRoute = (app) => {
188188
$match: {
189189
status: 'SUCCESS',
190190
createTime: {
191-
$gte: new Date(Date.now() - day * 24 * 60 * 60 * 1000)
191+
$gte: new Date(Date.now() - day * 24 * 60 * 60 * 1000 + 8 * 60 * 60 * 1000) // 补时差
192192
}
193193
}
194194
},
195+
{
196+
$addFields: {
197+
adjustedCreateTime: { $add: ['$createTime', 8 * 60 * 60 * 1000] }
198+
}
199+
},
195200
{
196201
$group: {
197202
_id: {
198-
year: { $year: '$createTime' },
199-
month: { $month: '$createTime' },
200-
day: { $dayOfMonth: '$createTime' }
203+
year: { $year: '$adjustedCreateTime' },
204+
month: { $month: '$adjustedCreateTime' },
205+
day: { $dayOfMonth: '$adjustedCreateTime' }
201206
},
202207
count: { $sum: '$price' }
203208
}
@@ -216,7 +221,8 @@ export const useUserRoute = (app) => {
216221
startCount += item.count;
217222
return {
218223
date: item.date,
219-
count: startCount
224+
total: startCount,
225+
count: item.count
220226
};
221227
});
222228

admin/src/Dashboard.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@ import dayjs from 'dayjs';
1616
const authStorageKey = 'tushan:auth';
1717
const PRICE_SCALE = 100000;
1818

19-
type fetchChatData = { count: number; date: string; increase?: number; increaseRate?: string };
19+
type fetchChatData = {
20+
count: number;
21+
total?: number;
22+
date: string;
23+
increase?: number;
24+
increaseRate?: string;
25+
};
2026

2127
type chatDataType = {
2228
date: string;
2329
userCount: number;
2430
userIncrease?: number;
2531
userIncreaseRate?: string;
32+
payTotal: number;
2633
payCount: number;
2734
};
2835

@@ -84,7 +91,8 @@ export const Dashboard: React.FC = React.memo(() => {
8491
userCount: item.count,
8592
userIncrease: item.increase,
8693
userIncreaseRate: item.increaseRate,
87-
payCount: pay ? pay.count / PRICE_SCALE : 0
94+
payCount: pay ? pay.count / PRICE_SCALE : 0,
95+
payTotal: pay?.total ? pay.total / PRICE_SCALE : 0
8896
};
8997
});
9098
setChatData(data);
@@ -208,10 +216,13 @@ const CustomTooltip = ({ active, payload }: any) => {
208216
用户总数: <strong>{data.userCount}</strong>
209217
</p>
210218
<p className="label">
211-
用户进入增长数量: <strong>{data.userIncrease}</strong>
219+
用户今日增长数量: <strong>{data.userIncrease}</strong>
220+
</p>
221+
<p className="label">
222+
今日支付: <strong>{data.payCount}</strong>
212223
</p>
213224
<p className="label">
214-
60天累计支付: <strong>{data.payCount}</strong>
225+
60天累计支付: <strong>{data.payTotal}</strong>
215226
</p>
216227
</div>
217228
);
@@ -233,7 +244,7 @@ const UserChart = ({ data }: { data: chatDataType[] }) => {
233244
<stop offset="5%" stopColor="#82ca9d" stopOpacity={0.8} />
234245
<stop offset="95%" stopColor="#82ca9d" stopOpacity={0} />
235246
</linearGradient>
236-
<linearGradient id="payCount" x1="0" y1="0" x2="0" y2="1">
247+
<linearGradient id="payTotal" x1="0" y1="0" x2="0" y2="1">
237248
<stop offset="5%" stopColor="#8884d8" stopOpacity={0.8} />
238249
<stop offset="95%" stopColor="#8884d8" stopOpacity={0} />
239250
</linearGradient>
@@ -251,10 +262,10 @@ const UserChart = ({ data }: { data: chatDataType[] }) => {
251262
/>
252263
<Area
253264
type="monotone"
254-
dataKey="payCount"
265+
dataKey="payTotal"
255266
stroke="#8884d8"
256267
fillOpacity={1}
257-
fill="url(#payCount)"
268+
fill="url(#payTotal)"
258269
/>
259270
</AreaChart>
260271
</ResponsiveContainer>

0 commit comments

Comments
 (0)