主动管理减慢了 Rails 应用程序的速度

发布于 2024-12-11 03:51:09 字数 282 浏览 0 评论 0原文

我在正在运行的 Rails 应用程序中安装了 active_admin gem。执行此操作后,应用程序的速度明显变慢。获取新页面大约需要 4-5 秒。某些功能已损坏。

这是否可能是由于主动管理依赖于设备以及因为我有自己的身份验证而产生的冲突?我已经有了一个用户模型,其中包含“current_user”等方法和登录功能。

换句话说,除非使用设备进行身份验证,否则您不应该使用主动管理吗?我在文档中没有看到任何与此相关的内容。

我使用的是 Rails 3.1、Postgresql 数据库(如果有的话)。

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.

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.

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.

I'm on Rails 3.1, Postgresql database, if that matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

五里雾 2024-12-18 03:51:09

Rails 3.1 中的速度变慢是一个已知问题,这主要是由于 Active Admin 与新版本交互的方式造成的资产管道。据我所知,问题是仅在开发模式下运行时才出现(因此当您部署到生产环境时它应该消失)。

开发中还存在内存泄漏问题,可能会影响性能。但我个人的经验是,这并不是主要的性能杀手。

为了克服开发中缓慢的环境问题,一种快速解决方法是安装 rails-dev-tweaks gem。当传入请求是资源请求(图像、CSS、JS 等)时,这将阻止 Rails 重新生成资源。

关于你的第二个问题:Active Admin 仅适用于设备。但完全可以在前端使用不同的身份验证机制,并且仅依赖 Active Admin 中的 Devise。您当然应该确保 Devise 和您自己的身份验证不会发生冲突。您可以更改设备和 Active Admin 以使用不同的方法来检索当前用户。默认情况下,活动管理员使用 current_admin_user - 而不是 current_user。您可以在 config/initializers/active_admin.rb 中更改 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.

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.).

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.

绮烟 2024-12-18 03:51:09

如果您的管理模型具有 belongs_tohas_many 关系,并且 ActiveAdmin 的默认行为实际上会将您的数据库加载到 RAM 中。建议您仅添加真正需要的过滤器。

为每个过滤器集合指定确切的字段还将大大减少查询执行时间和内存占用。默认情况下,ActiveAdmin 正在查找 :id 和 :name 属性。我应用此方法将一个查询从几秒缩短到 0.7 毫秒。是的!!

例如

filter :account, collection: Account.unscoped.select(‘id, name’)

If your admin models have belongs_to and has_many relationships and the default behavior of ActiveAdmin will practically load your database into RAM. It is recommended that you add only the filters truly needed.

Specifying the exact fields for each filter collection will also greatly reduce query execution time and memory footprint. By default, ActiveAdmin is looking for :id and :name attributes. One query I applied this to reduced from several seconds to .7ms. YES!!

e.g.

filter :account, collection: Account.unscoped.select(‘id, name’)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文