active_admin resources/index.html.arb 缓慢

发布于 2024-12-15 00:13:17 字数 1881 浏览 1 评论 0原文

使用 active_admin,我发现为具有许多记录的模型加载索引时速度很慢。我不确定这是否与其他报告的缓慢案例有关。

2011-11-10 13:26:14 rails[35848]  INFO: Started GET "/admin/articles" for 127.0.0.1 at Thu Nov 10 13:26:14 -0800 2011
2011-11-10 13:26:14 rails[35848]  INFO: Processing by Admin::ArticlesController#index as HTML
2011-11-10 13:26:14 rails[35848]  DEBUG: AdminUser Load (0.3ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
2011-11-10 13:26:14 rails[35848]  DEBUG: Article Load (381.2ms)  SELECT "articles".* FROM "articles" ORDER BY publish_date desc, guid desc, "articles".id desc LIMIT 30 OFFSET 0
2011-11-10 13:26:14 rails[35848]  DEBUG: SQL (0.5ms)  SELECT COUNT(*) FROM "articles"
2011-11-10 13:26:14 rails[35848]  DEBUG: CACHE (0.0ms)  SELECT COUNT(*) FROM "articles"
2011-11-10 13:26:14 rails[35848]  DEBUG: CACHE (0.0ms)  SELECT COUNT(*) FROM "articles"
2011-11-10 13:26:21 rails[35848]  DEBUG: PendingArticle Load (6602.8ms)  SELECT "pending_articles".* FROM "pending_articles" ORDER BY created_at desc
2011-11-10 13:26:41 rails[35848]  DEBUG: Domain Load (1.0ms)  SELECT "domains".* FROM "domains"
2011-11-10 13:26:41 rails[35848]  INFO: Rendered /Users/sorens/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activeadmin-0.3.4/app/views/active_admin/resource/index.html.arb (27605.5ms)
2011-11-10 13:26:41 rails[35848]  INFO: Completed 200 OK in 27645ms (Views: 20629.0ms | ActiveRecord: 6985.8ms)

这是对 /admin/articles 的请求。我的文章模型有一个 belongs_to :pending_article。待处理的文章有 has_one :article, :autosave =>;正确。

我有几个问题

(1) 我可以阻止这个额外的查询吗?我没有从文章的索引视图访问任何未决文章中的任何字段。似乎文章查询的范围是通过分页正确确定的,但对挂起的文章的后续查询似乎抓住了所有这些。

(2) 如果只显示 30 条记录,为什么 index.html.arb 的渲染需要 27 秒以上?

我正在使用 Ruby 1.8.7-p299、Rails 3.0.5 和 active_admin 0.3.4。上面的输出来自我的开发环境(在 Heroku 上需要更长的时间)。在上面的示例中,我有 10,708 篇文章和 17,648 篇待处理文章。

Using active_admin, I am witnessing slowness with respect to loading an index for a model that has many records. I am not sure that this related to the other reported cases of slowness.

2011-11-10 13:26:14 rails[35848]  INFO: Started GET "/admin/articles" for 127.0.0.1 at Thu Nov 10 13:26:14 -0800 2011
2011-11-10 13:26:14 rails[35848]  INFO: Processing by Admin::ArticlesController#index as HTML
2011-11-10 13:26:14 rails[35848]  DEBUG: AdminUser Load (0.3ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
2011-11-10 13:26:14 rails[35848]  DEBUG: Article Load (381.2ms)  SELECT "articles".* FROM "articles" ORDER BY publish_date desc, guid desc, "articles".id desc LIMIT 30 OFFSET 0
2011-11-10 13:26:14 rails[35848]  DEBUG: SQL (0.5ms)  SELECT COUNT(*) FROM "articles"
2011-11-10 13:26:14 rails[35848]  DEBUG: CACHE (0.0ms)  SELECT COUNT(*) FROM "articles"
2011-11-10 13:26:14 rails[35848]  DEBUG: CACHE (0.0ms)  SELECT COUNT(*) FROM "articles"
2011-11-10 13:26:21 rails[35848]  DEBUG: PendingArticle Load (6602.8ms)  SELECT "pending_articles".* FROM "pending_articles" ORDER BY created_at desc
2011-11-10 13:26:41 rails[35848]  DEBUG: Domain Load (1.0ms)  SELECT "domains".* FROM "domains"
2011-11-10 13:26:41 rails[35848]  INFO: Rendered /Users/sorens/.rvm/gems/ruby-1.8.7-p299@rails3/gems/activeadmin-0.3.4/app/views/active_admin/resource/index.html.arb (27605.5ms)
2011-11-10 13:26:41 rails[35848]  INFO: Completed 200 OK in 27645ms (Views: 20629.0ms | ActiveRecord: 6985.8ms)

this was a request for /admin/articles. my article model has a belongs_to :pending_article. pending_article has has_one :article, :autosave => true.

I have a few questions

(1) Can I prevent this additional query? I am not accessing any field in any pending_article from the index view of article. it seems that the article query is correctly scoped by pagination but the follow-on query to pending_article appears to grab them all.

(2) why does the render of index.html.arb take 27+ seconds if it is just showing 30 records?

I am using Ruby 1.8.7-p299, Rails 3.0.5 and active_admin 0.3.4. The above output is from my development environment (it takes even longer on Heroku). In the above example, I had 10,708 articles and 17,648 pending_articles.

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

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

发布评论

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

评论(1

向日葵 2024-12-22 00:13:17

默认情况下,该表单包含每个属性的过滤器,这意味着它正在尝试为所有待处理的文章创建一个漂亮的弹出窗口。不要只使用默认值,而是尝试使用以下命令定义过滤器列表:

ActiveAdmin.register Article do
  filter :title
end

并且一定要跳过未决的_文章。这应该会阻止它加载所有这些记录。

By default the form includes a filter for each attribute, which means it is trying to create a nice popup for all your pending articles. Instead of just using the default, try defining the filter list with:

ActiveAdmin.register Article do
  filter :title
end

And just be sure to skip the pending_articles. That should prevent it from loading all those records.

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