Rails rake db:seed 和 rake assets:precompile 在远程服务器上要花费很长的时间

flowerwrong · 2014年12月10日 · 2635 次阅读
  1. 之前用 ckeditor ,使用capistrano 3部署到远程服务器的时候每次都卡在rake assets:precompile,不知道有什么解决办法没有?
  2. 我到 ssh 到远程服务器后执行RAILS_ENV=production rake db:seed, 也会话费很长很长的时间,通常也是直接卡顿。 下面我在本地进行rake db:seed的时间和远程的时间,有什么解决办法吗?
# local
$ rake db:seed
========================================
start seeds
33.115783543
end seeds
========================================

========================================
# ssh to server
start seeds
378.131025
end seeds
========================================

seeds.rb

puts '==' * 20
puts 'start seeds'

time_start = Time.now


cats = [
  {name: "白酒", title: "白酒", content: "白酒", secret_field: "secret_field"},
  {name: "红酒", title: "红酒", content: "红酒", secret_field: "secret_field"},
  {name: "葡萄酒", title: "葡萄酒", content: "葡萄酒", secret_field: "secret_field"},
  {name: "其他", title: "其他", content: "其他", secret_field: "secret_field"}
]

cats.each do |c|
  Cat.create! c
end

1.upto(50).each do |i|
  if i == 1
    u = User.new(username: 'admin', email: '[email protected]',
                 password: '12345678', password_confirmation: '12345678')
    u.save
    u.confirm!
    u.add_role :admin
    Profile.create(:user_id => u.id, :mobile => "135604744#{u.id}", :tel => "5555#{u.id}", :province => '广东省', :city => '广州市', :region => 'xxx', :address => 'xxx', :fax => "55555")
  elsif Array(2..10).include?(i)
    u = User.new(:username => "provider#{i}", :email => "provider#{i}@gmail.com", :password => "12345678", :password_confirmation => "12345678")
    u.save
    u.confirm!
    u.add_role :provider
    Profile.create(:user_id => u.id, :mobile => "135604744#{u.id}", :tel => "5555#{u.id}", :province => '广东省', :city => '广州市', :region => 'xxx', :address => 'xxx', :fax => "55555")
  else
    u = User.new(:username => "customer#{i}", :email => "customer#{i}@gmail.com", :password => "12345678", :password_confirmation => "12345678")
    u.save
    u.confirm!
    u.add_role :customer
    Profile.create(:supplier_id => rand(10), :user_id => u.id, :mobile => "135604744#{u.id}", :tel => "5555#{u.id}", :province => '广东省', :city => '广州市', :region => 'xxx', :address => 'xxx', :fax => '55555')
  end
end

time_end = Time.now
time = time_end - time_start
puts time.to_s
puts 'end seeds'
puts '==' * 20

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号