Active Record运行所有查询两次

时间:2014-05-06 19:24:38

标签: ruby-on-rails

不知道为什么会在生产中发生这种情况:

更新这是来自rails控制台:

User.all
  User Load (0.5ms)  SELECT "users".* FROM "users"
  User Load (0.5ms)  SELECT "users".* FROM "users"
2.0.0-p451 :005 > User.first.destroy
  User Load (0.6ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
  User Load (0.6ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
   (0.2ms)  BEGIN
   (0.2ms)  BEGIN
  Discussion Load (60.4ms)  SELECT DISTINCT "discussions".* FROM "discussions" INNER JOIN "followers" ON "discussions"."id" = "followers"."discussion_id" WHERE "followers"."user_id" = $1  [["user_id", 1]]
  Discussion Load (60.4ms)  SELECT DISTINCT "discussions".* FROM "discussions" INNER JOIN "followers" ON "discussions"."id" = "followers"."discussion_id" WHERE "followers"."user_id" = $1  [["user_id", 1]]
  Reply Load (0.8ms)  SELECT "replies".* FROM "replies" WHERE "replies"."user_id" = $1  [["user_id", 1]]
  Reply Load (0.8ms)  SELECT "replies".* FROM "replies" WHERE "replies"."user_id" = $1  [["user_id", 1]]
  SQL (0.4ms)  DELETE FROM "users" WHERE "users"."id" = $1  [["id", 1]]
  SQL (0.4ms)  DELETE FROM "users" WHERE "users"."id" = $1  [["id", 1]]
   (0.5ms)  COMMIT
   (0.5ms)  COMMIT

我的制作设置:

  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.default_url_options = { host: 'xxx' }
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :authentication => :plain,
    :address => "xxx",
    :port => xxx,
    :domain => "xxx",
    :user_name => "xxx",
    :password => "xxx"
  }


  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.serve_static_assets = :false
  config.log_level = :debug
  config.assets.debug = true

希望有一些共同的问题?真奇怪不是吗?

1 个答案:

答案 0 :(得分:6)

我遇到了类似的问题,原来这是我为heroku安装的rails_12factor gem中的一个错误。只需将其设置为Gemfile

中的生产宝石
gem 'rails_12factor', group: :production