File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ def self.extended(base)
19
19
# currently collected. A false value indicates collecting is turned
20
20
# off. Otherwise it is an array of queries.
21
21
def logging_query_plan # :nodoc:
22
+ return yield unless logger
23
+
22
24
threshold = auto_explain_threshold_in_seconds
23
25
current = Thread . current
24
26
if threshold && current [ :available_queries_for_explain ] . nil?
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def connection
14
14
base . connection
15
15
end
16
16
17
- def test_logging_query_plan
17
+ def test_logging_query_plan_with_logger
18
18
base . logger . expects ( :warn ) . with do |message |
19
19
message . starts_with? ( 'EXPLAIN for:' )
20
20
end
@@ -24,6 +24,20 @@ def test_logging_query_plan
24
24
end
25
25
end
26
26
27
+ def test_logging_query_plan_without_logger
28
+ original = base . logger
29
+ base . logger = nil
30
+
31
+ base . logger . expects ( :warn ) . never
32
+
33
+ with_threshold ( 0 ) do
34
+ car = Car . where ( :name => 'honda' ) . first
35
+ assert_equal 'honda' , car . name
36
+ end
37
+ ensure
38
+ base . logger = original
39
+ end
40
+
27
41
def test_collect_queries_for_explain
28
42
base . auto_explain_threshold_in_seconds = nil
29
43
queries = Thread . current [ :available_queries_for_explain ] = [ ]
Original file line number Diff line number Diff line change @@ -1400,6 +1400,9 @@ A threshold of +nil+ disables automatic EXPLAINs.
1400
1400
The default threshold in development mode is 0.5 seconds, and +nil+ in test and
1401
1401
production modes.
1402
1402
1403
+ INFO. Automatic EXPLAIN gets disabled if Active Record has no logger, regardless
1404
+ of the value of the threshold.
1405
+
1403
1406
h5. Disabling Automatic EXPLAIN
1404
1407
1405
1408
Automatic EXPLAIN can be selectively silenced with +ActiveRecord::Base.silence_auto_explain+:
You can’t perform that action at this time.
0 commit comments