mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
disable automatic explain if there is no logger [closes #4671]
This commit is contained in:
@@ -22,6 +22,8 @@ module ActiveRecord
|
|||||||
# currently collected. A false value indicates collecting is turned
|
# currently collected. A false value indicates collecting is turned
|
||||||
# off. Otherwise it is an array of queries.
|
# off. Otherwise it is an array of queries.
|
||||||
def logging_query_plan # :nodoc:
|
def logging_query_plan # :nodoc:
|
||||||
|
return yield unless logger
|
||||||
|
|
||||||
threshold = auto_explain_threshold_in_seconds
|
threshold = auto_explain_threshold_in_seconds
|
||||||
current = Thread.current
|
current = Thread.current
|
||||||
if threshold && current[:available_queries_for_explain].nil?
|
if threshold && current[:available_queries_for_explain].nil?
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if ActiveRecord::Base.connection.supports_explain?
|
|||||||
base.connection
|
base.connection
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_logging_query_plan
|
def test_logging_query_plan_with_logger
|
||||||
base.logger.expects(:warn).with do |message|
|
base.logger.expects(:warn).with do |message|
|
||||||
message.starts_with?('EXPLAIN for:')
|
message.starts_with?('EXPLAIN for:')
|
||||||
end
|
end
|
||||||
@@ -24,6 +24,20 @@ if ActiveRecord::Base.connection.supports_explain?
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_logging_query_plan_without_logger
|
||||||
|
original = base.logger
|
||||||
|
base.logger = nil
|
||||||
|
|
||||||
|
base.logger.expects(:warn).never
|
||||||
|
|
||||||
|
with_threshold(0) do
|
||||||
|
car = Car.where(:name => 'honda').first
|
||||||
|
assert_equal 'honda', car.name
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
base.logger = original
|
||||||
|
end
|
||||||
|
|
||||||
def test_collect_queries_for_explain
|
def test_collect_queries_for_explain
|
||||||
base.auto_explain_threshold_in_seconds = nil
|
base.auto_explain_threshold_in_seconds = nil
|
||||||
queries = Thread.current[:available_queries_for_explain] = []
|
queries = Thread.current[:available_queries_for_explain] = []
|
||||||
|
|||||||
@@ -1400,6 +1400,9 @@ A threshold of +nil+ disables automatic EXPLAINs.
|
|||||||
The default threshold in development mode is 0.5 seconds, and +nil+ in test and
|
The default threshold in development mode is 0.5 seconds, and +nil+ in test and
|
||||||
production modes.
|
production modes.
|
||||||
|
|
||||||
|
INFO. Automatic EXPLAIN gets disabled if Active Record has no logger, regardless
|
||||||
|
of the value of the threshold.
|
||||||
|
|
||||||
h5. Disabling Automatic EXPLAIN
|
h5. Disabling Automatic EXPLAIN
|
||||||
|
|
||||||
Automatic EXPLAIN can be selectively silenced with +ActiveRecord::Base.silence_auto_explain+:
|
Automatic EXPLAIN can be selectively silenced with +ActiveRecord::Base.silence_auto_explain+:
|
||||||
|
|||||||
Reference in New Issue
Block a user