gpt4 book ai didi

ruby-on-rails - Active Record 运行所有查询两次

转载 作者:行者123 更新时间:2023-12-03 16:04:22 26 4
gpt4 key购买 nike

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

更新 这是来自 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

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

最佳答案

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

gem 'rails_12factor', group: :production

关于ruby-on-rails - Active Record 运行所有查询两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23503238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com