feat(usage): /admin/usage 支持查看已删除用户 + 打开速度与刷新优化#2908
Open
DaydreamCoding wants to merge 2 commits into
Open
Conversation
用户软删除后使用记录仍在,但身份(邮箱)被 ent 软删除拦截器隐藏。本次在 三条管理员只读路径定点穿透软删除过滤,并把删除状态传播到前端标记,零新表/ 迁移/回填: - 后端穿透:富化 usage 日志(loadUsers)、用户搜索(ListWithFilters + UserListFilters.IncludeDeleted)、点击详情(GetByIDIncludeDeleted / GetUserIncludeDeleted + getById ?include_deleted 分支) - 状态传播:service.User / dto.User 新增 DeletedAt;SearchUsers 标记 deleted - 前端:表格与余额弹窗展示"已删除"徽标、筛选下拉标注并排序、点击走 include_deleted;新增 i18n admin.usage.userDeletedBadge - 安全:普通用户 usage 仅查本人(无 PII 泄漏);主用户列表与默认 getById 行为不变(已删用户仍 404);仅 admin 搜索设 IncludeDeleted 后端 build / 三态 vet / unit 全量 / 仓储集成全绿;前端 typecheck / vitest / 改动文件 eslint 全清。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
根因:页面 mount 并发 6 个请求,其中 5 个在原始 usage_logs 上 live 聚合, 且有 1 个重复 getModelStats。优化(不引入预聚合): 前端 - UsageView 经 :model-options 下传 model 列表,移除 UsageFilters 重复的 getModelStats(mount 请求 6→5,少一次 usage_logs 全表 GROUP BY model) - 刷新/换筛选保留旧模型数据(invalidateModelStatsCache 只失效标记不清空数据), 图表不再闪空,刷新期间页面保持可交互 后端 - GetStatsWithFilters 4 条聚合 errgroup 并行(仅 *sql.DB 连接池路径,ent.Tx 顺序回退以保事务内不并发),endpoint 明细 best-effort;抑制取消级联噪声日志 - /admin/usage/stats 复用 dashboard 的 newSnapshotCache 30s 处理器层缓存,按 filters+窗口为 key;前端手动刷新带 nocache=1 强制回源(刷新=最新) 注:自合并提交 4c8396c 迁移而来,仅取"列表打开速度与刷新响应"部分;原提交的 "审计查看弹窗大 body 渲染"改动(AuditLogModal / audit-log-format / 审计 i18n) 依赖尚未迁移的审计功能(d8389ade),本次已排除。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
e19bee2 to
bf24b61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. feat:支持查看已删除用户的历史使用情况
用户软删除后使用记录仍在,但身份(邮箱)被 ent
软删除拦截器隐藏。本次在三条管理员只读路径定点穿透软删除过滤,并把删除状态传播到前端标记,零新表 / 迁移 / 回填:
loadUsers)、用户搜索(ListWithFilters+UserListFilters.IncludeDeleted)、点击详情(GetByIDIncludeDeleted/GetUserIncludeDeleted+getById ?include_deleted分支)
service.User/dto.User新增DeletedAt;SearchUsers标记 deletedinclude_deleted;新增 i18nadmin.usage.userDeletedBadgegetById行为不变(已删用户仍 404);仅 admin 搜索设IncludeDeleted2. perf:优化打开速度与刷新响应
根因:页面 mount 并发 6 个请求,其中 5 个在原始
usage_logs上 live 聚合,且有 1 个重复getModelStats。优化思路 ——不引入预聚合:
UsageView经:model-options下传 model 列表,移除UsageFilters重复的getModelStats(mount 请求6→5,少一次
usage_logs全表 GROUP BY model);刷新/换筛选保留旧模型数据(invalidateModelStatsCache只失效标记不清空),图表不再闪空,刷新期间页面保持可交互
GetStatsWithFilters4 条聚合用 errgroup 并行(仅*sql.DB连接池路径,ent.Tx顺序回退以保事务内不并发),endpoint 明细 best-effort,并抑制取消级联噪声日志;
/admin/usage/stats复用 dashboard 的newSnapshotCache30s 处理器层缓存(按 filters+窗口为 key),前端手动刷新带nocache=1强制回源(刷新=最新)测试
go build ./...、go vet(默认 + integration tag)、go test(handler/admin + repository)全部通过eslint(改动文件)、vue-tsctypecheck、vitest(UsageFilters / UsageTable / UsageView)全绿