每次修改资产中的样式表时,Rails的加载速度都非常慢

时间:2017-12-27 10:17:54

标签: ruby-on-rails

每次修改rails样式表时,它都会在开发模式下加载很长时间。

这是日志,正如您所看到的,加载需要90秒,即每次资产修改的平均时间。

请帮助提出可能的问题。

Started GET "/" for ::1 at 2017-12-27 17:54:35 +0800
Processing by StaticPagesController#home as HTML
[1m[35mCart Load (0.0ms)[0m  SELECT  "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1  [["id", 110]]
[1m[36mAddnew Load (0.0ms)[0m  [1mSELECT  "addnews".* FROM "addnews"  ORDER BY "addnews"."id" ASC LIMIT 1[0m
[1m[35mProduct Load (0.0ms)[0m  SELECT  "products".* FROM "products" WHERE "products"."id" = ? LIMIT 1  [["id", 10]]
[1m[36mAddnew Load (0.0ms)[0m  [1mSELECT  "addnews".* FROM "addnews"  ORDER BY "addnews"."id" ASC LIMIT 1 OFFSET 1[0m
[1m[35mCACHE (0.0ms)[0m  SELECT  "products".* FROM "products" WHERE "products"."id" = ? LIMIT 1  [["id", 10]]
[1m[36mAddnew Load (0.0ms)[0m  [1mSELECT  "addnews".* FROM "addnews"  ORDER BY "addnews"."id" ASC LIMIT 1 OFFSET 2[0m
[1m[35mCACHE (0.0ms)[0m  SELECT  "products".* FROM "products" WHERE "products"."id" = ? LIMIT 1  [["id", 10]]
Rendered static_pages/home.html.erb within layouts/application (1.0ms)
Rendered layouts/_shim.html.erb (1.0ms)
[1m[36m (0.0ms)[0m  [1mSELECT COUNT(*) FROM "line_items" WHERE "line_items"."cart_id" = ?[0m  [["cart_id", 110]]
[1m[35mLineItem Exists (0.0ms)[0m  SELECT  1 AS one FROM "line_items" WHERE "line_items"."cart_id" = ? LIMIT 1  [["cart_id", 110]]
[1m[36mLineItem Load (0.0ms)[0m  [1mSELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = ?[0m  [["cart_id", 110]]
Rendered layouts/_header_cart_in_total.html.erb (1.0ms)
Rendered layouts/_header_cart.html.erb (13.0ms)
Rendered layouts/_home_header.html.erb (34.0ms)
Rendered shared/_flash.html.erb (0.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 90627ms (Views: 90615.0ms | ActiveRecord: 0.0ms)


Started GET "/assets/application-46823b452df5e3c7c6257626147e5cf2aa1e9b157ec4229dc94afc4bcb358ad8.css" for ::1 at 2017-12-27 17:56:06 +0800

根据请求上传的development.rb参数。 rails版本是4.2.4,ruby版本是2.3.3。

Rails.application.configure do


# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false


config.consider_all_requests_local       = true
config.action_controller.perform_caching = true


config.action_mailer.show_previews = true
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

config.assets.debug = false

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
config.action_mailer.perform_deliveries = true


config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'localhost:3000'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
  :address              => 'smtp.gmail.com',
  :port                 => '587',
  :authentication       => :plain,
  :user_name            => ENV["GMAIL_USERNAME"],
  :password             => ENV["GMAIL_PASSWORD"],
  :domain               => 'localhost:3000',
  :enable_starttls_auto => true
}
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Enable the asset pipeline
end

1 个答案:

答案 0 :(得分:1)

您可以提高开发中的资产速度。 首先,确保CACHING已开启。

打开此文件config / environments / development.rb

config.action_controller.perform_caching = true

然后重新启动服务器。

资产可能编译速度很慢,但至少只能让它们慢慢编译一次,而不是每次都编译。要确保缓存资产,请确保已启用缓存。