-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize log subscribers to check if the log level is sufficient #7708
Changes from all commits
19f0e37
d47fde6
3785272
8e1b02f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
module ActiveRecord | ||
class LogSubscriber < ActiveSupport::LogSubscriber | ||
IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we can ignore these payloads. cc @fxn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SCHEMA was already being ignored. I'd like to ignore Explain as well because when a query triggers the auto explain by passing the threshold, the original query and the query plan will be logged. It's not that interesting to see the Explain query logged as well. By itself this isn't an issue, but there are other debugging gems that hook into ActiveRecord to force explain plans on every query which ends up logging quite a bit of useless queries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. |
||
|
||
def self.runtime=(value) | ||
Thread.current["active_record_sql_runtime"] = value | ||
Thread.current[:active_record_sql_runtime] = value | ||
end | ||
|
||
def self.runtime | ||
Thread.current["active_record_sql_runtime"] ||= 0 | ||
Thread.current[:active_record_sql_runtime] ||= 0 | ||
end | ||
|
||
def self.reset_runtime | ||
|
@@ -24,9 +26,9 @@ def sql(event) | |
|
||
payload = event.payload | ||
|
||
return if 'SCHEMA' == payload[:name] | ||
return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) | ||
|
||
name = '%s (%.1fms)' % [payload[:name], event.duration] | ||
name = "#{payload[:name]} (#{event.duration.round(1)}ms)" | ||
sql = payload[:sql].squeeze(' ') | ||
binds = nil | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to check
logger.info? || logger.debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log levels are a hierarchy so logger.info? should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks