perf(system): 项目授权校验改单行查询 + AuthController 切 FromCache
背景:feat/multi-tenant-project 联调发现 /admin-api/** 全线变慢, 尤其 get-permission-info 经常超时。根因是 ProjectSecurityWebFilter 每请求需校验"用户对项目是否授权",原实现走"拿全量 authorizedIds 再 contains"路径,超管分支还得 selectList 全表项目。Framework 层虽有 60s 本地缓存,cache miss 时仍要走 Feign HTTP 自调用 + 两次 DB。 优化: 1. 新增 ProjectService.isProjectAuthorized(userId, projectId) 单项校验: - 超管直通返回 true(不查任何表) - 普通用户走 (user_id, project_id) 唯一索引的 selectCount 单行查询 2. ProjectCommonApi / ProjectApiImpl / ProjectFrameworkService(Impl) 全链路新增 isProjectAuthorized Feign 接口 3. ProjectFrameworkServiceImpl 为 isProjectAuthorized 加 60s 本地 Guava 缓存(key=(userId,projectId));invalidateAuthorizedProjectCache 同步清理本用户所有条目 4. ProjectSecurityWebFilter 改调 isProjectAuthorized,消除每请求 拉全量列表的开销 5. ProjectServiceImpl.getDefaultProjectId 的 N 次 selectById 改成一次 selectByIds 批量 6. AuthController.getPermissionInfo 第 107 行 getUserRoleIdListByUserId → FromCache(yudao 原生小瑕疵顺手修) 预期收益: - Filter 热路径在 cache 命中时 0 次 DB,cache miss 时 1 次单行查询 - get-permission-info 消除一次无缓存 user_role DB 查询 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,4 +35,11 @@ public interface ProjectCommonApi {
|
||||
@Parameter(name = "userId", description = "用户编号", required = true)
|
||||
CommonResult<Long> getDefaultProjectId(@RequestParam("userId") Long userId);
|
||||
|
||||
@GetMapping(PREFIX + "/is-authorized")
|
||||
@Operation(summary = "校验该用户是否有权访问该项目")
|
||||
@Parameter(name = "userId", description = "用户编号", required = true)
|
||||
@Parameter(name = "projectId", description = "项目编号", required = true)
|
||||
CommonResult<Boolean> isProjectAuthorized(@RequestParam("userId") Long userId,
|
||||
@RequestParam("projectId") Long projectId);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user