bullet 8.1.3 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/README.md +19 -6
- data/lib/bullet/active_record70.rb +14 -0
- data/lib/bullet/active_record71.rb +14 -0
- data/lib/bullet/active_record72.rb +14 -0
- data/lib/bullet/active_record80.rb +14 -0
- data/lib/bullet/active_record81.rb +14 -0
- data/lib/bullet/{active_record60.rb → active_record82.rb} +74 -49
- data/lib/bullet/dependency.rb +10 -58
- data/lib/bullet/detector/association.rb +9 -9
- data/lib/bullet/detector/counter_cache.rb +2 -2
- data/lib/bullet/detector/n_plus_one_query.rb +1 -1
- data/lib/bullet/rack.rb +41 -3
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +68 -28
- metadata +31 -9
- data/lib/bullet/active_record4.rb +0 -197
- data/lib/bullet/active_record41.rb +0 -191
- data/lib/bullet/active_record42.rb +0 -262
- data/lib/bullet/active_record5.rb +0 -294
- data/lib/bullet/active_record52.rb +0 -278
- data/lib/bullet/active_record61.rb +0 -310
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5c5aff8226198c501ed0c0a3e9d71138bd896f9956cf072b0f92fef79b125c7
|
|
4
|
+
data.tar.gz: 90209fe95da7ad96e110cfdabb96a91a9c403ef9e5824df2877aeab20239f020
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98dbc38b0e5f77f61617e75bab2b92838bbead761421681791711c917f61282e6ae29fe70fabe645ef8685344a879535fb4634451ff1bb35d560b0fd8a9c3a12
|
|
7
|
+
data.tar.gz: 49f2ebf88e0d99386ebd35a82403ece35167e9ac253013244f9ded4fe76de6b14ea070741847b6048b90ca1e15b6765430a56a180d8f6e6961383be035d08b38
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
## Unreleased
|
|
2
2
|
|
|
3
|
+
## 8.3.1 (10/24/2026)
|
|
4
|
+
|
|
5
|
+
* Avoid redefining the `footer_position` getter
|
|
6
|
+
* Avoid the CGI loading warning on Ruby 4
|
|
7
|
+
* Keep request state separate for sibling fibers on one thread
|
|
8
|
+
|
|
9
|
+
## 8.3.0 (10/10/2026)
|
|
10
|
+
|
|
11
|
+
* Add support for ActiveRecord 8.2
|
|
12
|
+
|
|
13
|
+
## 8.2.0 (08/29/2026)
|
|
14
|
+
|
|
15
|
+
* Add thread-safe `Bullet.pause`, `Bullet.resume`, `Bullet.paused?`, and `Bullet.skip` APIs
|
|
16
|
+
* Add configurable footer positioning
|
|
17
|
+
* Fix unused eager loading false positives when N+1 detection is disabled
|
|
18
|
+
* Fix unused eager loading false positives for conditional `has_many :through` associations
|
|
19
|
+
* Fix Ruby 4.0 compatibility issues
|
|
20
|
+
* Drop support for ActiveRecord versions older than 7 and Mongoid versions older than 8
|
|
21
|
+
|
|
3
22
|
## 8.1.3 (06/02/2026)
|
|
4
23
|
|
|
5
|
-
* Handle inversed polymorphic belongs_to false positives
|
|
24
|
+
* Handle inversed polymorphic `belongs_to` false positives
|
|
6
25
|
|
|
7
26
|
## 8.1.2 (05/25/2026)
|
|
8
27
|
|
data/README.md
CHANGED
|
@@ -69,6 +69,7 @@ config.after_initialize do
|
|
|
69
69
|
Bullet.airbrake = true
|
|
70
70
|
Bullet.rollbar = true
|
|
71
71
|
Bullet.add_footer = true
|
|
72
|
+
Bullet.footer_position = 'bottom_left' # or 'bottom_right', 'top_left', 'top_right'
|
|
72
73
|
Bullet.skip_html_injection = false
|
|
73
74
|
Bullet.skip_http_headers = false
|
|
74
75
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
|
@@ -97,6 +98,7 @@ The code above will enable all of the Bullet notification systems:
|
|
|
97
98
|
* `Bullet.airbrake`: add notifications to airbrake
|
|
98
99
|
* `Bullet.rollbar`: add notifications to rollbar
|
|
99
100
|
* `Bullet.add_footer`: adds the details in the bottom left corner of the page. Double click the footer or use close button to hide footer.
|
|
101
|
+
* `Bullet.footer_position`: position of the footer on the page. Valid values are 'bottom_left' (default), 'bottom_right', 'top_left', or 'top_right'. This is useful when the default position clashes with browser UI elements like Chrome's URL preview.
|
|
100
102
|
* `Bullet.skip_html_injection`: prevents Bullet from injecting code into the returned HTML. This must be false for receiving alerts, showing the footer or console logging.
|
|
101
103
|
* `Bullet.skip_http_headers`: don't add headers to API requests, and remove the javascript that relies on them. Note that this prevents bullet from logging warnings to the browser console or updating the footer.
|
|
102
104
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
|
@@ -137,23 +139,34 @@ Bullet.add_safelist :type => :unused_eager_loading, :class_name => "Post", :asso
|
|
|
137
139
|
Bullet.add_safelist :type => :counter_cache, :class_name => "Country", :association => :cities
|
|
138
140
|
```
|
|
139
141
|
|
|
142
|
+
## Skip Bullet in specific actions
|
|
143
|
+
|
|
140
144
|
If you want to skip bullet in some specific controller actions, you can
|
|
141
|
-
|
|
145
|
+
use `Bullet.skip`, which is thread-safe and works correctly in multi-threaded
|
|
146
|
+
environments like Puma.
|
|
142
147
|
|
|
143
148
|
```ruby
|
|
144
149
|
class ApplicationController < ActionController::Base
|
|
145
150
|
around_action :skip_bullet, if: -> { defined?(Bullet) }
|
|
146
151
|
|
|
147
152
|
def skip_bullet
|
|
148
|
-
|
|
149
|
-
Bullet.enable = false
|
|
150
|
-
yield
|
|
151
|
-
ensure
|
|
152
|
-
Bullet.enable = previous_value
|
|
153
|
+
Bullet.skip { yield }
|
|
153
154
|
end
|
|
154
155
|
end
|
|
155
156
|
```
|
|
156
157
|
|
|
158
|
+
For more granular control, you can also use `Bullet.pause` and `Bullet.resume`:
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
Bullet.pause # Temporarily disable detection for current thread
|
|
162
|
+
Bullet.resume # Re-enable detection for current thread
|
|
163
|
+
Bullet.paused? # Check if detection is paused for current thread
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Note**: Do not toggle `Bullet.enable` at runtime, as it modifies a global
|
|
167
|
+
flag that is not thread-safe. Use `Bullet.skip`, `Bullet.pause`, or
|
|
168
|
+
`Bullet.start_request`/`Bullet.end_request` instead.
|
|
169
|
+
|
|
157
170
|
## Log
|
|
158
171
|
|
|
159
172
|
The Bullet log `log/bullet.log` will look something like this:
|
|
@@ -109,6 +109,20 @@ module Bullet
|
|
|
109
109
|
super
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
def through_preloaders
|
|
114
|
+
if Bullet.start? && !defined?(@through_preloaders)
|
|
115
|
+
preloaders = super
|
|
116
|
+
preloaders.each do |preloader|
|
|
117
|
+
reflection_name = preloader.send(:reflection).name
|
|
118
|
+
preloader.send(:owners).each do |owner|
|
|
119
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
super
|
|
124
|
+
end
|
|
125
|
+
end
|
|
112
126
|
end
|
|
113
127
|
)
|
|
114
128
|
|
|
@@ -109,6 +109,20 @@ module Bullet
|
|
|
109
109
|
super
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
def through_preloaders
|
|
114
|
+
if Bullet.start? && !defined?(@through_preloaders)
|
|
115
|
+
preloaders = super
|
|
116
|
+
preloaders.each do |preloader|
|
|
117
|
+
reflection_name = preloader.send(:reflection).name
|
|
118
|
+
preloader.send(:owners).each do |owner|
|
|
119
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
super
|
|
124
|
+
end
|
|
125
|
+
end
|
|
112
126
|
end
|
|
113
127
|
)
|
|
114
128
|
|
|
@@ -109,6 +109,20 @@ module Bullet
|
|
|
109
109
|
super
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
def through_preloaders
|
|
114
|
+
if Bullet.start? && !defined?(@through_preloaders)
|
|
115
|
+
preloaders = super
|
|
116
|
+
preloaders.each do |preloader|
|
|
117
|
+
reflection_name = preloader.send(:reflection).name
|
|
118
|
+
preloader.send(:owners).each do |owner|
|
|
119
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
super
|
|
124
|
+
end
|
|
125
|
+
end
|
|
112
126
|
end
|
|
113
127
|
)
|
|
114
128
|
|
|
@@ -109,6 +109,20 @@ module Bullet
|
|
|
109
109
|
super
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
def through_preloaders
|
|
114
|
+
if Bullet.start? && !defined?(@through_preloaders)
|
|
115
|
+
preloaders = super
|
|
116
|
+
preloaders.each do |preloader|
|
|
117
|
+
reflection_name = preloader.send(:reflection).name
|
|
118
|
+
preloader.send(:owners).each do |owner|
|
|
119
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
super
|
|
124
|
+
end
|
|
125
|
+
end
|
|
112
126
|
end
|
|
113
127
|
)
|
|
114
128
|
|
|
@@ -109,6 +109,20 @@ module Bullet
|
|
|
109
109
|
super
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
def through_preloaders
|
|
114
|
+
if Bullet.start? && !defined?(@through_preloaders)
|
|
115
|
+
preloaders = super
|
|
116
|
+
preloaders.each do |preloader|
|
|
117
|
+
reflection_name = preloader.send(:reflection).name
|
|
118
|
+
preloader.send(:owners).each do |owner|
|
|
119
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
super
|
|
124
|
+
end
|
|
125
|
+
end
|
|
112
126
|
end
|
|
113
127
|
)
|
|
114
128
|
|
|
@@ -16,8 +16,8 @@ module Bullet
|
|
|
16
16
|
require 'active_record'
|
|
17
17
|
::ActiveRecord::Base.extend(
|
|
18
18
|
Module.new do
|
|
19
|
-
def find_by_sql(
|
|
20
|
-
result = super
|
|
19
|
+
def find_by_sql(*args, **kwargs, &block)
|
|
20
|
+
result = super(*args, **kwargs, &block)
|
|
21
21
|
if Bullet.start?
|
|
22
22
|
if result.is_a? Array
|
|
23
23
|
if result.size > 1
|
|
@@ -61,25 +61,32 @@ module Bullet
|
|
|
61
61
|
end
|
|
62
62
|
)
|
|
63
63
|
|
|
64
|
-
::ActiveRecord::Associations::Preloader.prepend(
|
|
64
|
+
::ActiveRecord::Associations::Preloader::Batch.prepend(
|
|
65
65
|
Module.new do
|
|
66
|
-
def
|
|
66
|
+
def call
|
|
67
67
|
if Bullet.start?
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
@preloaders.each do |preloader|
|
|
69
|
+
preloader.records.each { |record|
|
|
70
|
+
Bullet::Detector::Association.add_object_associations(record, preloader.associations)
|
|
71
|
+
}
|
|
72
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(preloader.records, preloader.associations)
|
|
72
73
|
end
|
|
73
74
|
end
|
|
74
75
|
super
|
|
75
76
|
end
|
|
77
|
+
end
|
|
78
|
+
)
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
::ActiveRecord::Associations::Preloader::Branch.prepend(
|
|
81
|
+
Module.new do
|
|
82
|
+
def preloaders_for_reflection(reflection, reflection_records)
|
|
78
83
|
if Bullet.start?
|
|
79
|
-
|
|
80
|
-
if
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
reflection_records.compact!
|
|
85
|
+
if reflection_records.first.class.name !~ /^HABTM_/
|
|
86
|
+
reflection_records.each { |record|
|
|
87
|
+
Bullet::Detector::Association.add_object_associations(record, reflection.name)
|
|
88
|
+
}
|
|
89
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(reflection_records, reflection.name)
|
|
83
90
|
end
|
|
84
91
|
end
|
|
85
92
|
super
|
|
@@ -89,25 +96,41 @@ module Bullet
|
|
|
89
96
|
|
|
90
97
|
::ActiveRecord::Associations::Preloader::ThroughAssociation.prepend(
|
|
91
98
|
Module.new do
|
|
92
|
-
def
|
|
93
|
-
if Bullet.start? && !defined?(@
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
def source_preloaders
|
|
100
|
+
if Bullet.start? && !defined?(@source_preloaders)
|
|
101
|
+
preloaders = super
|
|
102
|
+
preloaders.each do |preloader|
|
|
103
|
+
reflection_name = preloader.send(:reflection).name
|
|
104
|
+
preloader.send(:owners).each do |owner|
|
|
97
105
|
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
98
106
|
end
|
|
99
107
|
end
|
|
108
|
+
else
|
|
109
|
+
super
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def through_preloaders
|
|
114
|
+
if Bullet.start? && !defined?(@through_preloaders)
|
|
115
|
+
preloaders = super
|
|
116
|
+
preloaders.each do |preloader|
|
|
117
|
+
reflection_name = preloader.send(:reflection).name
|
|
118
|
+
preloader.send(:owners).each do |owner|
|
|
119
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection_name)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
super
|
|
100
124
|
end
|
|
101
|
-
super
|
|
102
125
|
end
|
|
103
126
|
end
|
|
104
127
|
)
|
|
105
128
|
|
|
106
129
|
::ActiveRecord::Associations::JoinDependency.prepend(
|
|
107
130
|
Module.new do
|
|
108
|
-
def instantiate(
|
|
131
|
+
def instantiate(*args, **kwargs, &block)
|
|
109
132
|
@bullet_eager_loadings = {}
|
|
110
|
-
records = super
|
|
133
|
+
records = super(*args, **kwargs, &block)
|
|
111
134
|
|
|
112
135
|
if Bullet.start?
|
|
113
136
|
@bullet_eager_loadings.each do |_klazz, eager_loadings_hash|
|
|
@@ -121,7 +144,8 @@ module Bullet
|
|
|
121
144
|
records
|
|
122
145
|
end
|
|
123
146
|
|
|
124
|
-
def construct(
|
|
147
|
+
def construct(*args, **kwargs, &block)
|
|
148
|
+
ar_parent, parent, row = args
|
|
125
149
|
if Bullet.start?
|
|
126
150
|
unless ar_parent.nil?
|
|
127
151
|
parent.children.each do |node|
|
|
@@ -144,12 +168,13 @@ module Bullet
|
|
|
144
168
|
end
|
|
145
169
|
end
|
|
146
170
|
|
|
147
|
-
super
|
|
171
|
+
super(*args, **kwargs, &block)
|
|
148
172
|
end
|
|
149
173
|
|
|
150
174
|
# call join associations
|
|
151
|
-
def construct_model(
|
|
152
|
-
|
|
175
|
+
def construct_model(*args, **kwargs, &block)
|
|
176
|
+
record, node = args
|
|
177
|
+
result = super(*args, **kwargs, &block)
|
|
153
178
|
|
|
154
179
|
if Bullet.start?
|
|
155
180
|
associations = [node.reflection.name]
|
|
@@ -178,6 +203,13 @@ module Bullet
|
|
|
178
203
|
end
|
|
179
204
|
super
|
|
180
205
|
end
|
|
206
|
+
|
|
207
|
+
def inversed_from_queries(record)
|
|
208
|
+
if Bullet.start? && inversable?(record)
|
|
209
|
+
Bullet::Detector::NPlusOneQuery.add_inversed_object(owner, reflection.name)
|
|
210
|
+
end
|
|
211
|
+
super
|
|
212
|
+
end
|
|
181
213
|
end
|
|
182
214
|
)
|
|
183
215
|
|
|
@@ -200,11 +232,7 @@ module Bullet
|
|
|
200
232
|
end
|
|
201
233
|
end
|
|
202
234
|
end
|
|
203
|
-
|
|
204
|
-
Bullet::Detector::Association.add_call_object_associations(owner, reflection.name)
|
|
205
|
-
else
|
|
206
|
-
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
207
|
-
end
|
|
235
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
208
236
|
if records.first.class.name !~ /^HABTM_/
|
|
209
237
|
if records.size > 1
|
|
210
238
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
|
@@ -235,31 +263,28 @@ module Bullet
|
|
|
235
263
|
::ActiveRecord::Associations::SingularAssociation.prepend(
|
|
236
264
|
Module.new do
|
|
237
265
|
# call has_one and belongs_to associations
|
|
238
|
-
def
|
|
239
|
-
result = super
|
|
266
|
+
def reader
|
|
267
|
+
result = super
|
|
240
268
|
|
|
241
269
|
if Bullet.start?
|
|
242
270
|
if owner.class.name !~ /^HABTM_/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
end
|
|
271
|
+
if is_a? ::ActiveRecord::Associations::ThroughAssociation
|
|
272
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
|
273
|
+
association = owner.association(reflection.through_reflection.name)
|
|
274
|
+
Array.wrap(association.target).each do |through_record|
|
|
275
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
|
276
|
+
end
|
|
250
277
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
end
|
|
278
|
+
if reflection.through_reflection != through_reflection
|
|
279
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
|
|
254
280
|
end
|
|
255
281
|
end
|
|
256
|
-
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
end
|
|
282
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
283
|
+
|
|
284
|
+
if Bullet::Detector::NPlusOneQuery.impossible?(owner)
|
|
285
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
|
286
|
+
else
|
|
287
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result) if result
|
|
263
288
|
end
|
|
264
289
|
end
|
|
265
290
|
end
|
data/lib/bullet/dependency.rb
CHANGED
|
@@ -13,22 +13,8 @@ module Bullet
|
|
|
13
13
|
def active_record_version
|
|
14
14
|
@active_record_version ||=
|
|
15
15
|
begin
|
|
16
|
-
if
|
|
17
|
-
|
|
18
|
-
elsif active_record41?
|
|
19
|
-
'active_record41'
|
|
20
|
-
elsif active_record42?
|
|
21
|
-
'active_record42'
|
|
22
|
-
elsif active_record50?
|
|
23
|
-
'active_record5'
|
|
24
|
-
elsif active_record51?
|
|
25
|
-
'active_record5'
|
|
26
|
-
elsif active_record52?
|
|
27
|
-
'active_record52'
|
|
28
|
-
elsif active_record60?
|
|
29
|
-
'active_record60'
|
|
30
|
-
elsif active_record61?
|
|
31
|
-
'active_record61'
|
|
16
|
+
if active_record6_or_older?
|
|
17
|
+
raise "Bullet no longer supports active_record #{::ActiveRecord::VERSION::STRING}"
|
|
32
18
|
elsif active_record70?
|
|
33
19
|
'active_record70'
|
|
34
20
|
elsif active_record71?
|
|
@@ -39,6 +25,8 @@ module Bullet
|
|
|
39
25
|
'active_record80'
|
|
40
26
|
elsif active_record81?
|
|
41
27
|
'active_record81'
|
|
28
|
+
elsif active_record82?
|
|
29
|
+
'active_record82'
|
|
42
30
|
else
|
|
43
31
|
raise "Bullet does not support active_record #{::ActiveRecord::VERSION::STRING} yet"
|
|
44
32
|
end
|
|
@@ -66,16 +54,8 @@ module Bullet
|
|
|
66
54
|
end
|
|
67
55
|
end
|
|
68
56
|
|
|
69
|
-
def
|
|
70
|
-
active_record? && ::ActiveRecord::VERSION::MAJOR
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def active_record5?
|
|
74
|
-
active_record? && ::ActiveRecord::VERSION::MAJOR == 5
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def active_record6?
|
|
78
|
-
active_record? && ::ActiveRecord::VERSION::MAJOR == 6
|
|
57
|
+
def active_record6_or_older?
|
|
58
|
+
active_record? && ::ActiveRecord::VERSION::MAJOR < 7
|
|
79
59
|
end
|
|
80
60
|
|
|
81
61
|
def active_record7?
|
|
@@ -86,38 +66,6 @@ module Bullet
|
|
|
86
66
|
active_record? && ::ActiveRecord::VERSION::MAJOR == 8
|
|
87
67
|
end
|
|
88
68
|
|
|
89
|
-
def active_record40?
|
|
90
|
-
active_record4? && ::ActiveRecord::VERSION::MINOR == 0
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def active_record41?
|
|
94
|
-
active_record4? && ::ActiveRecord::VERSION::MINOR == 1
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def active_record42?
|
|
98
|
-
active_record4? && ::ActiveRecord::VERSION::MINOR == 2
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def active_record50?
|
|
102
|
-
active_record5? && ::ActiveRecord::VERSION::MINOR == 0
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def active_record51?
|
|
106
|
-
active_record5? && ::ActiveRecord::VERSION::MINOR == 1
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def active_record52?
|
|
110
|
-
active_record5? && ::ActiveRecord::VERSION::MINOR == 2
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def active_record60?
|
|
114
|
-
active_record6? && ::ActiveRecord::VERSION::MINOR == 0
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def active_record61?
|
|
118
|
-
active_record6? && ::ActiveRecord::VERSION::MINOR == 1
|
|
119
|
-
end
|
|
120
|
-
|
|
121
69
|
def active_record70?
|
|
122
70
|
active_record7? && ::ActiveRecord::VERSION::MINOR == 0
|
|
123
71
|
end
|
|
@@ -138,6 +86,10 @@ module Bullet
|
|
|
138
86
|
active_record8? && ::ActiveRecord::VERSION::MINOR == 1
|
|
139
87
|
end
|
|
140
88
|
|
|
89
|
+
def active_record82?
|
|
90
|
+
active_record8? && ::ActiveRecord::VERSION::MINOR == 2
|
|
91
|
+
end
|
|
92
|
+
|
|
141
93
|
def mongoid4x?
|
|
142
94
|
mongoid? && ::Mongoid::VERSION =~ /\A4/
|
|
143
95
|
end
|
|
@@ -8,7 +8,7 @@ module Bullet
|
|
|
8
8
|
class << self
|
|
9
9
|
def add_object_associations(object, associations)
|
|
10
10
|
return unless Bullet.start?
|
|
11
|
-
return
|
|
11
|
+
return unless Bullet.n_plus_one_query_enable? || Bullet.unused_eager_loading_enable?
|
|
12
12
|
return unless object.bullet_primary_key_value
|
|
13
13
|
|
|
14
14
|
Bullet.debug(
|
|
@@ -21,7 +21,7 @@ module Bullet
|
|
|
21
21
|
|
|
22
22
|
def add_call_object_associations(object, associations)
|
|
23
23
|
return unless Bullet.start?
|
|
24
|
-
return
|
|
24
|
+
return unless Bullet.n_plus_one_query_enable? || Bullet.unused_eager_loading_enable?
|
|
25
25
|
return unless object.bullet_primary_key_value
|
|
26
26
|
|
|
27
27
|
Bullet.debug(
|
|
@@ -36,7 +36,7 @@ module Bullet
|
|
|
36
36
|
# that the objects may cause N+1 query.
|
|
37
37
|
# e.g. { Post => ["Post:1", "Post:2"] }
|
|
38
38
|
def possible_objects
|
|
39
|
-
|
|
39
|
+
Bullet.state[:bullet_possible_objects]
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
# impossible_objects keep the class to objects relationships
|
|
@@ -45,7 +45,7 @@ module Bullet
|
|
|
45
45
|
# if find collection returns only one object, then the object is impossible object,
|
|
46
46
|
# impossible_objects are used to avoid treating 1+1 query to N+1 query.
|
|
47
47
|
def impossible_objects
|
|
48
|
-
|
|
48
|
+
Bullet.state[:bullet_impossible_objects]
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
private
|
|
@@ -56,7 +56,7 @@ module Bullet
|
|
|
56
56
|
# the object_associations keep all associations that may be or may no be
|
|
57
57
|
# unpreload associations or unused preload associations.
|
|
58
58
|
def object_associations
|
|
59
|
-
|
|
59
|
+
Bullet.state[:bullet_object_associations]
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# call_object_associations keep the object relationships
|
|
@@ -64,27 +64,27 @@ module Bullet
|
|
|
64
64
|
# e.g. { "Post:1" => [:comments] }
|
|
65
65
|
# they are used to detect unused preload associations.
|
|
66
66
|
def call_object_associations
|
|
67
|
-
|
|
67
|
+
Bullet.state[:bullet_call_object_associations]
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
# inversed_objects keeps object relationships
|
|
71
71
|
# that association is inversed.
|
|
72
72
|
# e.g. { "Comment:1" => ["post"] }
|
|
73
73
|
def inversed_objects
|
|
74
|
-
|
|
74
|
+
Bullet.state[:bullet_inversed_objects]
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
# eager_loadings keep the object relationships
|
|
78
78
|
# that the associations are preloaded by find :include.
|
|
79
79
|
# e.g. { ["Post:1", "Post:2"] => [:comments, :user] }
|
|
80
80
|
def eager_loadings
|
|
81
|
-
|
|
81
|
+
Bullet.state[:bullet_eager_loadings]
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
# call_stacks keeps stacktraces where querie-objects were called from.
|
|
85
85
|
# e.g. { 'Object:111' => [SomeProject/app/controllers/...] }
|
|
86
86
|
def call_stacks
|
|
87
|
-
|
|
87
|
+
Bullet.state[:bullet_call_stacks]
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
end
|
|
@@ -46,11 +46,11 @@ module Bullet
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def possible_objects
|
|
49
|
-
|
|
49
|
+
Bullet.state[:bullet_counter_possible_objects]
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def impossible_objects
|
|
53
|
-
|
|
53
|
+
Bullet.state[:bullet_counter_impossible_objects]
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
private
|
|
@@ -15,7 +15,7 @@ module Bullet
|
|
|
15
15
|
# if it is, keeps this unpreload associations and caller.
|
|
16
16
|
def call_association(object, associations, caller_stack = nil, inversed: false)
|
|
17
17
|
return unless Bullet.start?
|
|
18
|
-
return unless Bullet.n_plus_one_query_enable?
|
|
18
|
+
return unless Bullet.n_plus_one_query_enable? || Bullet.unused_eager_loading_enable?
|
|
19
19
|
return unless object.bullet_primary_key_value
|
|
20
20
|
|
|
21
21
|
# Record before early-returns so legitimate reads that bypass SQL
|