From a2f33a6c3569940ad17cd2f7f6e7120736a12369 Mon Sep 17 00:00:00 2001 From: fawney19 Date: Sun, 4 Jan 2026 22:42:58 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8B=86=E5=88=86=E7=83=AD=E5=8A=9B?= =?UTF-8?q?=E5=9B=BE=E4=B8=BA=E7=8B=AC=E7=AB=8B=E6=8E=A5=E5=8F=A3=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Redis=20=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增独立热力图 API 端点 (/api/admin/usage/heatmap, /api/users/me/usage/heatmap) - 添加 Redis 缓存层 (5分钟 TTL),减少数据库查询 - 用户角色变更时清除热力图缓存 - 前端并行加载统计数据和热力图,添加加载/错误状态显示 - 修复 cache_decorator 缺少 JSON 解析错误处理的问题 - 更新 docker-compose 启动命令提示 --- frontend/src/api/me.ts | 9 ++ frontend/src/api/usage.ts | 9 ++ .../usage/components/ActivityHeatmapCard.vue | 19 ++- .../usage/composables/useUsageData.ts | 8 +- frontend/src/features/usage/types.ts | 6 +- frontend/src/views/shared/Usage.vue | 46 ++++++- src/api/admin/usage/routes.py | 34 ++++-- src/api/admin/users/routes.py | 7 ++ src/api/user_me/routes.py | 35 ++++-- src/config/constants.py | 3 + src/database/database.py | 2 +- src/services/usage/service.py | 112 ++++++++++++++++++ src/utils/cache_decorator.py | 12 +- 13 files changed, 271 insertions(+), 31 deletions(-) diff --git a/frontend/src/api/me.ts b/frontend/src/api/me.ts index 9e22d07..9bd9426 100644 --- a/frontend/src/api/me.ts +++ b/frontend/src/api/me.ts @@ -286,5 +286,14 @@ export const meApi = { }> { const response = await apiClient.get('/api/users/me/usage/interval-timeline', { params }) return response.data + }, + + /** + * 获取活跃度热力图数据(用户) + * 后端已缓存5分钟 + */ + async getActivityHeatmap(): Promise { + const response = await apiClient.get('/api/users/me/usage/heatmap') + return response.data } } diff --git a/frontend/src/api/usage.ts b/frontend/src/api/usage.ts index ed76022..610bb11 100644 --- a/frontend/src/api/usage.ts +++ b/frontend/src/api/usage.ts @@ -198,5 +198,14 @@ export const usageApi = { const params = ids?.length ? { ids: ids.join(',') } : {} const response = await apiClient.get('/api/admin/usage/active', { params }) return response.data + }, + + /** + * 获取活跃度热力图数据(管理员) + * 后端已缓存5分钟 + */ + async getActivityHeatmap(): Promise { + const response = await apiClient.get('/api/admin/usage/heatmap') + return response.data } } diff --git a/frontend/src/features/usage/components/ActivityHeatmapCard.vue b/frontend/src/features/usage/components/ActivityHeatmapCard.vue index 7cf99c7..afcc35e 100644 --- a/frontend/src/features/usage/components/ActivityHeatmapCard.vue +++ b/frontend/src/features/usage/components/ActivityHeatmapCard.vue @@ -18,8 +18,22 @@ +
+ + 加载中... +
+
+ + 加载失败 +
@@ -34,6 +48,7 @@