![](/img/trans.png)
[英]Rails: Reloading code in development environment gives a “ApplicationHelper has been removed from the module tree but is still active!” error
[英]Rails 6.1 development environment not printing query trigger code line with verbose active
我有兩條線:
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
ActiveRecord::Base.verbose_query_logs = true
在我的config/environments/development/rb
但在我的開發日志中,sql 查詢記錄如下:
2022-08-10 08:35:18.536410 D [74:puma srv tp 004] (0.006ms) ActiveRecord -- Model Load -- { :sql => "SELECT ....", :binds => { .... }, :allocations => 1, :cached => true }
我有一個 N+1 查詢問題要修復,但缺少關於代碼中哪一行觸發查詢的信息,所以這對我沒有多大幫助。
我還嘗試使用帶有配置的 active-record-query-trace gem:
if Rails.env.development?
ActiveRecordQueryTrace.enabled = true
ActiveRecordQueryTrace.level = :full
ActiveRecordQueryTrace.colorize = true # No colorization (default)
ActiveRecordQueryTrace.colorize = :light_purple
# Optional: other gem config options go here
end
但我發現查詢的記錄方式完全沒有變化。
如何啟用觸發查詢的行的日志記錄?
謝謝
如果您想知道進行數據庫查詢的參考點,我曾經使用名為 Marginalia 的 gem。 我在 Rails 6 中使用它,它完全符合您的要求。
從我正在閱讀的內容來看,Rails 7 包含此功能作為本機功能(我可能會添加這非常棒)。
我找到了一個討論這個的鏈接: Rails 7 includes Marginalia
他們的例子說:
# config/application.rb
module Saeloun
class Application < Rails::Application
config.active_record.query_log_tags_enabled = true
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.