ActiveAdmin 在开发环境中非常慢
Posted
技术标签:
【中文标题】ActiveAdmin 在开发环境中非常慢【英文标题】:ActiveAdmin very slow in development environment 【发布时间】:2020-08-03 22:07:31 【问题描述】:我有一个使用 ActiveAdmin gem 的应用程序。
我们实际上有 3 个命名空间和超过 100 个ActiveAdmin.register Model
轨道 5.0.7
主动管理员 2.4
该应用程序在生产环境中运行良好,但是当我们处于开发模式时,每次代码更改时,重新加载都很慢。
反射轨迹可能不相关: 我深入研究了一下,似乎代码开始为“浏览器请求”的 html 部分重新加载一次,但之后它为页面要求的每个资产重新加载多次。它同时发生。代码一次重新加载了很多次,重新加载开始很慢。
这里是我刚刚进行代码修改时的输出日志:
Started GET "/admin/tickets" for ::1 at 2020-04-21 11:35:23 +0200
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
Processing by Admin::TicketsController#index as HTML
AdminUser Load (4.8ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Rendering /Users/baptibenz/.rvm/gems/ruby-2.4.4/gems/activeadmin-2.4.0/app/views/active_admin/resource/index.html.arb
(2.3ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "tickets" LIMIT $1 OFFSET $2) subquery_for_count [["LIMIT", 30], ["OFFSET", 0]]
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "tickets" LIMIT $1 OFFSET $2) subquery_for_count [["LIMIT", 30], ["OFFSET", 0]]
(2.1ms) SELECT COUNT(*) FROM "tickets"
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "tickets" LIMIT $1 OFFSET $2) subquery_for_count [["LIMIT", 30], ["OFFSET", 0]]
Ticket Load (2.6ms) SELECT "tickets".* FROM "tickets" ORDER BY "tickets"."id" desc LIMIT $1 OFFSET $2 [["LIMIT", 30], ["OFFSET", 0]]
Listing Load (2.9ms) SELECT "listings".* FROM "listings" WHERE "listings"."id" = $1 LIMIT $2 [["id", 22015], ["LIMIT", 1]]
Team Load (2.1ms) SELECT "teams".* FROM "teams" WHERE "teams"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
TicketCategory Load (9.6ms) SELECT "ticket_categories".* FROM "ticket_categories" WHERE "ticket_categories"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Rendered admin/tickets/_index.arb (179.4ms)
TicketCategory Load (5.0ms) SELECT "ticket_categories".* FROM "ticket_categories"
Team Load (3.1ms) SELECT "teams".* FROM "teams"
AdminUser Load (28.2ms) SELECT "admin_users".* FROM "admin_users"
Rendered layouts/_analytics.erb (0.7ms)
Rendered /Users/baptibenz/.rvm/gems/ruby-2.4.4/gems/activeadmin-2.4.0/app/views/active_admin/resource/index.html.arb (470.9ms)
Completed 200 OK in 649ms (Views: 466.9ms | ActiveRecord: 68.7ms)
(3.1ms) BEGIN
(2.2ms) COMMIT
Started GET "/assets/jquery.xdan.datetimepicker.css" for ::1 at 2020-04-21 11:35:36 +0200
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
Started GET "/assets/active_admin.js" for ::1 at 2020-04-21 11:35:43 +0200
(2.1ms) BEGIN
(2.0ms) COMMIT
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
Started GET "/assets/active_admin/print.css" for ::1 at 2020-04-21 11:35:54 +0200
Started GET "/assets/active_admin.css" for ::1 at 2020-04-21 11:35:54 +0200
(3.4ms) BEGIN
(2.5ms) COMMIT
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
(2.4ms) BEGIN
(4.5ms) BEGIN
(5.2ms) COMMIT
(3.8ms) COMMIT
Started GET "/assets/active_admin/orderable.png" for ::1 at 2020-04-21 11:36:35 +0200
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
Started GET "/assets/active_admin/nested_menu_arrow.gif" for ::1 at 2020-04-21 11:36:56 +0200
(3.1ms) BEGIN
(3.1ms) COMMIT
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
Started GET "/assets/chosen-sprite@2x.png" for ::1 at 2020-04-21 11:37:19 +0200
(2.9ms) BEGIN
(2.5ms) COMMIT
Creating scope :customer_relations. Overwriting existing method AdminUser.customer_relations.
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: already initialized constant ActiveAdmin::CSVBuilder::DEFAULT_COLUMNS_OPTIONS
/Users/baptibenz/dev/backend/app/admin/lib/component.rb:3: warning: previous definition of DEFAULT_COLUMNS_OPTIONS was here
(2.2ms) BEGIN
(4.9ms) COMMIT
正如您在日期中看到的那样,它非常慢
如果您需要更多信息,请告诉我 :-)
【问题讨论】:
从你 git 浏览器开始添加你的开发日志,直到它完成加载。 @matanco 添加 :-) 我看不慢,这个日志是修改后的? @matanco 是的,这是在进行更改之后:在第一次通话开始GET "/admin/tickets"
(2020-04-21 11:35:23) 和最后一次通话开始之间(每个 cal 触发重新加载应用程序):GET "/assets/chosen-sprite@2x.png"
(2020-04-21 11:37:19) 我等了大约 2 分钟页面完成加载
你能告诉我这个范围:AdminUser.customer_relations
以及你的开发人员的桌子大小吗?
【参考方案1】:
您似乎遇到了ActiveAdmin#5787。 TL;DR 这在 Rails 5.2 和 ActiveAdmin 2.6 中消失了。
【讨论】:
另外,FWIW,我在大型商店看到的一种策略是使用环境变量选择性地仅注册开发中的资源子集。以上是关于ActiveAdmin 在开发环境中非常慢的主要内容,如果未能解决你的问题,请参考以下文章
ModelSerializer 在 Django REST 框架中非常慢