We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetAuthInfo 方法获取时间过长, 希望能够优化一下
Originally posted by @tegohang in #168 (comment)
The text was updated successfully, but these errors were encountered:
原先慢的原因,是依赖于数据库查询所有模块-模块的所有功能,还涉及模块树遍历,确实很垃圾
在系统初始化的时候,已经根据最新代码通过IModuleInfoPicker.Pickup()提取了ModuleInfo[]信息,此信息包含了Module树,Module->Function[]的信息,可以缓存复用,解决上面慢的原因 实现如下:
IModuleInfoPicker.Pickup()
ModuleInfo[]
public string[] GetAuthInfo() { IServiceProvider provider = HttpContext.RequestServices; IModuleHandler moduleHandler = provider.GetRequiredService<IModuleHandler>(); IFunctionAuthorization functionAuthorization = provider.GetService<IFunctionAuthorization>(); ModuleInfo[] moduleInfos = moduleHandler.ModuleInfos; //先查找出所有有权限的模块 List<ModuleInfo> authModules = new List<ModuleInfo>(); foreach (ModuleInfo moduleInfo in moduleInfos) { bool hasAuth = moduleInfo.DependOnFunctions.All(m => functionAuthorization.Authorize(m, User).IsOk); if (moduleInfo.DependOnFunctions.Length == 0 || hasAuth) { authModules.Add(moduleInfo); } } List<string> codes = new List<string>(); foreach (ModuleInfo moduleInfo in authModules) { string fullCode = moduleInfo.FullCode; //模块下边有功能,或者拥有子模块 if (moduleInfo.DependOnFunctions.Length > 0 || authModules.Any(m => m.FullCode.Length > fullCode.Length && m.FullCode.Contains(fullCode) && m.DependOnFunctions.Length > 0)) { codes.AddIfNotExist(fullCode); } } return codes.ToArray(); }
Sorry, something went wrong.
feat(auth): 优化AuthController.GetAuthInfo方法的实现 #227
ba33738
No branches or pull requests
GetAuthInfo 方法获取时间过长, 希望能够优化一下
Originally posted by @tegohang in #168 (comment)
The text was updated successfully, but these errors were encountered: