CanCan 授权:性能问题
暂时忘记能力的定义,只关注能力的“检查”(使用“授权!”),我看到 CanCan 添加了大约 400 毫秒,用于简单地检查用户是否对特定主题/模型具有某种能力。
这是预期的吗(我假设不是)?或者,我可能做的事情不太正确吗?
我在 Rails 控制台中使用了 CURL 和 Benchmark.measure{} 来验证这一点,并且我相当肯定(基于各种测试)额外的开销是 CanCan 特定的。
想法?
Forgetting the definition of abilities for a second and just focusing on the "checking" of abilities (using "authorize! "), I see about 400 ms added by CanCan for simply checking if the user has a certain ability on a particular subject/model.
Is this expected (I am assuming not)? Or, is it possible I am doing something not quite right?
I've used both CURL and Benchmark.measure{} from within the Rails Console to verify this and I am reasonably positive (based on various tests) that the additional overhead is CanCan-specific.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想当你有一个巨大的能力文件时可能会发生这种情况。
考虑按照此处的说明进行拆分: https://github.com/ryanb/cancan/wiki/管理命名空间
I guess this could happen when you have a huge ability file.
Consider splitting it following instructions here: https://github.com/ryanb/cancan/wiki/Admin-Namespace
我也遇到过这个问题。我现在已经尝试过缓存,但我将考虑仅向用户模型添加布尔值以获得权限。
I've had this issue as well. I've tried caching for now but I'm going to look at just adding booleans to the User model for permissions.