问题描述
我在一个可用的Rails应用程序中安装了active_admin gem。完成此操作后,该应用程序明显变慢了。获取新页面大约需要4-5秒。某些功能已损坏。
I installed the active_admin gem in a working rails application. After doing this, the app noticeably slowed down. It takes around 4-5 seconds to get a new page. Some functionality is broken.
这是否可能是由于主动管理员依赖于设计以及由于我拥有自己的身份验证而引起的冲突?我已经有一个使用 current_user之类的方法和登录功能的用户模型。
Is this possibly due to active admin relying on devise and conflicts arising because I have my own authentication? I already had a User model with methods like 'current_user' and sign in features.
换句话说,除非使用devise进行身份验证,否则不应该使用主动管理吗?我在文档中没有看到任何关于此的信息。
In other words, are you not supposed to use active admin unless using devise for authentication? I don't see anything about this in the documentation.
如果重要的话,我正在使用Rails 3.1和Postgresql数据库。
I'm on Rails 3.1, Postgresql database, if that matters.
推荐答案
Rails 3.1的速度下降是,主要是由于Active Admin的方式与新的资产管道交互。据我所知,问题仅在以开发模式运行时才会出现(因此,当部署到生产环境时,它应该消失了。)
The slow down in Rails 3.1 is a known issue that is mostly due to the the way Active Admin interacts with the new Asset Pipeline. The issue is - as far as I'm aware - only present when running in development mode (so when you deploy to production it should go away).
开发中的,可能会对性能产生影响。但是我个人的经验是,这不是主要的性能杀手。
There is also a memory leak issue in development that might have a performance impact. But my personal experience is that this isn't the main performance killer.
要克服开发中缓慢的环境问题,一种快速的解决方法是安装 gem。当传入的请求是资产请求(图像,css,js等)时,这将防止Rails重新生成资产。
To overcome the slow environment issue in development, one quick fix is to install the rails-dev-tweaks gem. This will prevent Rails from regenerating assets when the incoming request is an asset request (images, css, js etc.).
关于第二个问题:Active Admin仅适用精心设计但是,完全有可能在您的前端中使用其他身份验证机制,并且仅依赖Active Admin中的Devise。您应确保Devise和您自己的身份验证不冲突。您可以将devise和Active Admin更改为使用其他方法来检索当前用户。默认情况下,Active Admin使用 current_admin_user
-而不是 current_user
。您可以在 config / initializers / active_admin.rb
中更改Active Admin的身份验证设置。有关更多信息,请阅读。
As to your second question: Active Admin only works with devise. But it is entirely possible to use a different authentication mechanism in your frontend and only rely on Devise in Active Admin. You should of cause ensure that Devise and your own authentication does not conflict. You can change devise and Active Admin to use a different method for retrieving the current user. By default Active Admin uses current_admin_user
- not current_user
. You can change the authentication settings for Active Admin in config/initializers/active_admin.rb
. For more info, read the authentication documentation.
这篇关于主动管理员减慢Rails应用程序的运行速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!