bullet 6.0.2 → 6.1.4
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/.travis.yml +3 -1
- data/CHANGELOG.md +25 -0
- data/Gemfile.rails-6.0 +1 -1
- data/Gemfile.rails-6.1 +15 -0
- data/README.md +12 -2
- data/lib/bullet.rb +31 -20
- data/lib/bullet/active_job.rb +1 -3
- data/lib/bullet/active_record4.rb +9 -23
- data/lib/bullet/active_record41.rb +7 -19
- data/lib/bullet/active_record42.rb +8 -16
- data/lib/bullet/active_record5.rb +188 -170
- data/lib/bullet/active_record52.rb +187 -161
- data/lib/bullet/active_record60.rb +194 -175
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +17 -23
- data/lib/bullet/dependency.rb +42 -34
- data/lib/bullet/detector/association.rb +24 -18
- data/lib/bullet/detector/base.rb +1 -2
- data/lib/bullet/detector/counter_cache.rb +10 -6
- data/lib/bullet/detector/n_plus_one_query.rb +18 -8
- data/lib/bullet/detector/unused_eager_loading.rb +5 -2
- data/lib/bullet/mongoid4x.rb +3 -7
- data/lib/bullet/mongoid5x.rb +3 -7
- data/lib/bullet/mongoid6x.rb +3 -7
- data/lib/bullet/mongoid7x.rb +3 -7
- data/lib/bullet/notification/base.rb +14 -18
- data/lib/bullet/notification/n_plus_one_query.rb +2 -4
- data/lib/bullet/notification/unused_eager_loading.rb +2 -4
- data/lib/bullet/rack.rb +23 -15
- data/lib/bullet/stack_trace_filter.rb +7 -16
- data/lib/bullet/version.rb +1 -1
- data/lib/generators/bullet/install_generator.rb +23 -23
- data/perf/benchmark.rb +8 -14
- data/spec/bullet/detector/counter_cache_spec.rb +6 -6
- data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
- data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -6
- data/spec/bullet/notification/base_spec.rb +1 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +16 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
- data/spec/bullet/rack_spec.rb +133 -7
- data/spec/bullet/registry/association_spec.rb +2 -2
- data/spec/bullet/registry/base_spec.rb +1 -1
- data/spec/bullet_spec.rb +10 -29
- data/spec/integration/active_record/association_spec.rb +77 -122
- data/spec/integration/counter_cache_spec.rb +10 -30
- data/spec/integration/mongoid/association_spec.rb +18 -32
- data/spec/models/attachment.rb +5 -0
- data/spec/models/folder.rb +1 -2
- data/spec/models/group.rb +1 -2
- data/spec/models/page.rb +1 -2
- data/spec/models/submission.rb +1 -0
- data/spec/models/user.rb +1 -0
- data/spec/models/writer.rb +1 -2
- data/spec/spec_helper.rb +6 -10
- data/spec/support/bullet_ext.rb +8 -9
- data/spec/support/mongo_seed.rb +2 -16
- data/spec/support/sqlite_seed.rb +8 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ea4e863bfe254dde17af73253ffe7041cd2b2dabee2dad05d1eccb6904f229
|
4
|
+
data.tar.gz: 284dcd1a516922384bdaf1b3dd9e6a5e6776c213c3ecbc9ca41b223c5b92d36b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26c43bfdac9582f059d067d4f56d4d85ed28416654ff5fd4686bf9977cbfbc8d92f887079954662e904fbe3d1b861d02482ac2fefac30a859fbdad8c3833e225
|
7
|
+
data.tar.gz: 48decfa9d28b9936f5c1f39c669b6e8061fae649f9036c29d4b28138083a43db8739f3b73bb9c390e9f6baea62aa1f66f79e8ced69cf13e789b8f116c101f25f
|
data/.travis.yml
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
3
2
|
rvm:
|
4
3
|
- 2.3.0
|
@@ -29,3 +28,6 @@ matrix:
|
|
29
28
|
gemfile: Gemfile.rails-4.0
|
30
29
|
env:
|
31
30
|
- DB=sqlite
|
31
|
+
before_install:
|
32
|
+
- "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
|
33
|
+
- gem install bundler -v '< 2'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
## Next Release
|
2
2
|
|
3
|
+
## 6.1.4 (02/26/2021)
|
4
|
+
|
5
|
+
* Added an option to stop adding HTTP headers to API requests
|
6
|
+
|
7
|
+
## 6.1.3 (01/21/2021)
|
8
|
+
|
9
|
+
* Consider ThroughAssociation at SingularAssociation like CollectionAssociation
|
10
|
+
* Add xhr_script only when add_footer is enabled
|
11
|
+
|
12
|
+
## 6.1.2 (12/12/2020)
|
13
|
+
|
14
|
+
* Revert "Make whitelist thread safe"
|
15
|
+
|
16
|
+
## 6.1.1 (12/12/2020)
|
17
|
+
|
18
|
+
* Add support Rails 6.1
|
19
|
+
* Make whitelist thread safe
|
20
|
+
|
21
|
+
## 6.1.0 (12/28/2019)
|
22
|
+
|
23
|
+
* Add skip_html_injection flag
|
24
|
+
* Remove writer hack in active_record6
|
25
|
+
* Use modern includes syntax in warnings
|
26
|
+
* Fix warning: The last argument is used as the keyword parameter
|
27
|
+
|
3
28
|
## 6.0.2 (08/20/2019)
|
4
29
|
|
5
30
|
* Fully support Rails 6.0
|
data/Gemfile.rails-6.0
CHANGED
data/Gemfile.rails-6.1
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rails', '~> 6.1.0'
|
6
|
+
gem 'sqlite3'
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
+
gem 'activerecord-import'
|
9
|
+
|
10
|
+
gem "rspec"
|
11
|
+
|
12
|
+
platforms :rbx do
|
13
|
+
gem 'rubysl', '~> 2.0'
|
14
|
+
gem 'rubinius-developer_tools'
|
15
|
+
end
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Bullet
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/bullet)
|
4
|
+
[](http://travis-ci.org/flyerhzm/bullet)
|
5
5
|
[](https://awesomecode.io/repos/flyerhzm/bullet)
|
6
6
|
[](http://coderwall.com/flyerhzm)
|
7
7
|
|
@@ -37,6 +37,13 @@ or add it into a Gemfile (Bundler):
|
|
37
37
|
gem 'bullet', group: 'development'
|
38
38
|
```
|
39
39
|
|
40
|
+
enable the Bullet gem with generate command
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
bundle exec rails g bullet:install
|
44
|
+
```
|
45
|
+
The generate command will auto generate the default configuration and may ask to include in the test environment as well. See below for custom configuration.
|
46
|
+
|
40
47
|
**Note**: make sure `bullet` gem is added after activerecord (rails) and
|
41
48
|
mongoid.
|
42
49
|
|
@@ -63,6 +70,7 @@ config.after_initialize do
|
|
63
70
|
Bullet.airbrake = true
|
64
71
|
Bullet.rollbar = true
|
65
72
|
Bullet.add_footer = true
|
73
|
+
Bullet.skip_html_injection = false
|
66
74
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
67
75
|
Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
|
68
76
|
Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
|
@@ -85,6 +93,8 @@ The code above will enable all of the Bullet notification systems:
|
|
85
93
|
* `Bullet.rollbar`: add notifications to rollbar
|
86
94
|
* `Bullet.sentry`: add notifications to sentry
|
87
95
|
* `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.
|
96
|
+
* `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.
|
97
|
+
* `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.
|
88
98
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
89
99
|
* `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
|
90
100
|
Each item can be a string (match substring), a regex, or an array where the first item is a path to match, and the second
|
data/lib/bullet.rb
CHANGED
@@ -23,7 +23,7 @@ module Bullet
|
|
23
23
|
BULLET_DEBUG = 'BULLET_DEBUG'
|
24
24
|
TRUE = 'true'
|
25
25
|
|
26
|
-
if defined?
|
26
|
+
if defined?(Rails::Railtie)
|
27
27
|
class BulletRailtie < Rails::Railtie
|
28
28
|
initializer 'bullet.configure_rails_initialization' do |app|
|
29
29
|
app.middleware.use Bullet::Rack
|
@@ -32,28 +32,36 @@ module Bullet
|
|
32
32
|
end
|
33
33
|
|
34
34
|
class << self
|
35
|
-
attr_writer :n_plus_one_query_enable,
|
35
|
+
attr_writer :n_plus_one_query_enable,
|
36
|
+
:unused_eager_loading_enable,
|
37
|
+
:counter_cache_enable,
|
38
|
+
:stacktrace_includes,
|
39
|
+
:stacktrace_excludes,
|
40
|
+
:skip_html_injection
|
36
41
|
attr_reader :whitelist
|
37
|
-
attr_accessor :add_footer, :
|
42
|
+
attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers
|
38
43
|
|
39
|
-
available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
|
40
|
-
|
41
|
-
delegate(*available_notifiers)
|
44
|
+
available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
|
45
|
+
available_notifiers_options = { to: UniformNotifier }
|
46
|
+
delegate(*available_notifiers, **available_notifiers_options)
|
42
47
|
|
43
48
|
def raise=(should_raise)
|
44
49
|
UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
|
45
50
|
end
|
46
51
|
|
47
|
-
DETECTORS = [
|
48
|
-
|
49
|
-
|
52
|
+
DETECTORS = [
|
53
|
+
Bullet::Detector::NPlusOneQuery,
|
54
|
+
Bullet::Detector::UnusedEagerLoading,
|
55
|
+
Bullet::Detector::CounterCache
|
56
|
+
].freeze
|
50
57
|
|
51
58
|
def enable=(enable)
|
52
59
|
@enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
|
60
|
+
|
53
61
|
if enable?
|
54
62
|
reset_whitelist
|
55
|
-
unless
|
56
|
-
self.
|
63
|
+
unless orm_patches_applied
|
64
|
+
self.orm_patches_applied = true
|
57
65
|
Bullet::Mongoid.enable if mongoid?
|
58
66
|
Bullet::ActiveRecord.enable if active_record?
|
59
67
|
end
|
@@ -65,7 +73,7 @@ module Bullet
|
|
65
73
|
end
|
66
74
|
|
67
75
|
def app_root
|
68
|
-
(defined?(::Rails.root) ? Rails.root.to_s : Dir.pwd).to_s
|
76
|
+
@app_root ||= (defined?(::Rails.root) ? Rails.root.to_s : Dir.pwd).to_s
|
69
77
|
end
|
70
78
|
|
71
79
|
def n_plus_one_query_enable?
|
@@ -81,11 +89,11 @@ module Bullet
|
|
81
89
|
end
|
82
90
|
|
83
91
|
def stacktrace_includes
|
84
|
-
@stacktrace_includes
|
92
|
+
@stacktrace_includes ||= []
|
85
93
|
end
|
86
94
|
|
87
95
|
def stacktrace_excludes
|
88
|
-
@stacktrace_excludes
|
96
|
+
@stacktrace_excludes ||= []
|
89
97
|
end
|
90
98
|
|
91
99
|
def add_whitelist(options)
|
@@ -174,9 +182,7 @@ module Bullet
|
|
174
182
|
|
175
183
|
def gather_inline_notifications
|
176
184
|
responses = []
|
177
|
-
for_each_active_notifier_with_notification
|
178
|
-
responses << notification.notify_inline
|
179
|
-
end
|
185
|
+
for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
|
180
186
|
responses.join("\n")
|
181
187
|
end
|
182
188
|
|
@@ -190,9 +196,7 @@ module Bullet
|
|
190
196
|
|
191
197
|
def footer_info
|
192
198
|
info = []
|
193
|
-
notification_collector.collection.each
|
194
|
-
info << notification.short_notice
|
195
|
-
end
|
199
|
+
notification_collector.collection.each { |notification| info << notification.short_notice }
|
196
200
|
info
|
197
201
|
end
|
198
202
|
|
@@ -214,6 +218,7 @@ module Bullet
|
|
214
218
|
|
215
219
|
def profile
|
216
220
|
return_value = nil
|
221
|
+
|
217
222
|
if Bullet.enable?
|
218
223
|
begin
|
219
224
|
Bullet.start_request
|
@@ -235,6 +240,12 @@ module Bullet
|
|
235
240
|
UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
|
236
241
|
end
|
237
242
|
|
243
|
+
def inject_into_page?
|
244
|
+
return false if defined?(@skip_html_injection) && @skip_html_injection
|
245
|
+
|
246
|
+
console_enabled? || add_footer
|
247
|
+
end
|
248
|
+
|
238
249
|
private
|
239
250
|
|
240
251
|
def for_each_active_notifier_with_notification
|
data/lib/bullet/active_job.rb
CHANGED
@@ -5,7 +5,7 @@ module Bullet
|
|
5
5
|
def self.enable
|
6
6
|
require 'active_record'
|
7
7
|
::ActiveRecord::Base.class_eval do
|
8
|
-
class <<self
|
8
|
+
class << self
|
9
9
|
alias_method :origin_find_by_sql, :find_by_sql
|
10
10
|
def find_by_sql(sql, binds = [])
|
11
11
|
result = origin_find_by_sql(sql, binds)
|
@@ -49,9 +49,7 @@ module Bullet
|
|
49
49
|
|
50
50
|
::ActiveRecord::Persistence.class_eval do
|
51
51
|
def _create_record_with_bullet(*args)
|
52
|
-
_create_record_without_bullet(*args).tap
|
53
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
|
54
|
-
end
|
52
|
+
_create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
|
55
53
|
end
|
56
54
|
alias_method_chain :_create_record, :bullet
|
57
55
|
end
|
@@ -62,13 +60,12 @@ module Bullet
|
|
62
60
|
alias_method :origin_initialize, :initialize
|
63
61
|
def initialize(records, associations, preload_scope = nil)
|
64
62
|
origin_initialize(records, associations, preload_scope)
|
63
|
+
|
65
64
|
if Bullet.start?
|
66
65
|
records = [records].flatten.compact.uniq
|
67
66
|
return if records.empty?
|
68
67
|
|
69
|
-
records.each
|
70
|
-
Bullet::Detector::Association.add_object_associations(record, associations)
|
71
|
-
end
|
68
|
+
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
72
69
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
73
70
|
end
|
74
71
|
end
|
@@ -81,9 +78,7 @@ module Bullet
|
|
81
78
|
records = origin_find_with_associations
|
82
79
|
if Bullet.start?
|
83
80
|
associations = (eager_load_values + includes_values).uniq
|
84
|
-
records.each
|
85
|
-
Bullet::Detector::Association.add_object_associations(record, associations)
|
86
|
-
end
|
81
|
+
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
87
82
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
88
83
|
end
|
89
84
|
records
|
@@ -128,17 +123,13 @@ module Bullet
|
|
128
123
|
# call one to many associations
|
129
124
|
alias_method :origin_load_target, :load_target
|
130
125
|
def load_target
|
131
|
-
if Bullet.start?
|
132
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
133
|
-
end
|
126
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
134
127
|
origin_load_target
|
135
128
|
end
|
136
129
|
|
137
130
|
alias_method :origin_include?, :include?
|
138
131
|
def include?(object)
|
139
|
-
if Bullet.start?
|
140
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
141
|
-
end
|
132
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
142
133
|
origin_include?(object)
|
143
134
|
end
|
144
135
|
end
|
@@ -156,9 +147,7 @@ module Bullet
|
|
156
147
|
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
157
148
|
alias_method :origin_empty?, :empty?
|
158
149
|
def empty?
|
159
|
-
if Bullet.start? && !loaded?
|
160
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
161
|
-
end
|
150
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !loaded?
|
162
151
|
origin_empty?
|
163
152
|
end
|
164
153
|
end
|
@@ -183,12 +172,9 @@ module Bullet
|
|
183
172
|
|
184
173
|
def has_cached_counter?(reflection = reflection())
|
185
174
|
result = origin_has_cached_counter?(reflection)
|
186
|
-
if Bullet.start? && !result
|
187
|
-
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
|
188
|
-
end
|
175
|
+
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) if Bullet.start? && !result
|
189
176
|
result
|
190
177
|
end
|
191
|
-
|
192
178
|
end
|
193
179
|
end
|
194
180
|
end
|
@@ -5,7 +5,7 @@ module Bullet
|
|
5
5
|
def self.enable
|
6
6
|
require 'active_record'
|
7
7
|
::ActiveRecord::Base.class_eval do
|
8
|
-
class <<self
|
8
|
+
class << self
|
9
9
|
alias_method :origin_find_by_sql, :find_by_sql
|
10
10
|
def find_by_sql(sql, binds = [])
|
11
11
|
result = origin_find_by_sql(sql, binds)
|
@@ -51,9 +51,7 @@ module Bullet
|
|
51
51
|
|
52
52
|
::ActiveRecord::Persistence.class_eval do
|
53
53
|
def _create_record_with_bullet(*args)
|
54
|
-
_create_record_without_bullet(*args).tap
|
55
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
|
56
|
-
end
|
54
|
+
_create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
|
57
55
|
end
|
58
56
|
alias_method_chain :_create_record, :bullet
|
59
57
|
end
|
@@ -65,9 +63,7 @@ module Bullet
|
|
65
63
|
if Bullet.start?
|
66
64
|
records.compact!
|
67
65
|
if records.first.class.name !~ /^HABTM_/
|
68
|
-
records.each
|
69
|
-
Bullet::Detector::Association.add_object_associations(record, association)
|
70
|
-
end
|
66
|
+
records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
|
71
67
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
|
72
68
|
end
|
73
69
|
end
|
@@ -84,9 +80,7 @@ module Bullet
|
|
84
80
|
records = origin_find_with_associations
|
85
81
|
if Bullet.start?
|
86
82
|
associations = (eager_load_values + includes_values).uniq
|
87
|
-
records.each
|
88
|
-
Bullet::Detector::Association.add_object_associations(record, associations)
|
89
|
-
end
|
83
|
+
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
90
84
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
91
85
|
end
|
92
86
|
records
|
@@ -131,9 +125,7 @@ module Bullet
|
|
131
125
|
# call one to many associations
|
132
126
|
alias_method :origin_load_target, :load_target
|
133
127
|
def load_target
|
134
|
-
if Bullet.start?
|
135
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
136
|
-
end
|
128
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !@inversed
|
137
129
|
origin_load_target
|
138
130
|
end
|
139
131
|
|
@@ -147,9 +139,7 @@ module Bullet
|
|
147
139
|
|
148
140
|
alias_method :origin_include?, :include?
|
149
141
|
def include?(object)
|
150
|
-
if Bullet.start?
|
151
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
152
|
-
end
|
142
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
153
143
|
origin_include?(object)
|
154
144
|
end
|
155
145
|
end
|
@@ -173,9 +163,7 @@ module Bullet
|
|
173
163
|
alias_method :origin_count_records, :count_records
|
174
164
|
def count_records
|
175
165
|
result = has_cached_counter?
|
176
|
-
if Bullet.start? && !result
|
177
|
-
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
|
178
|
-
end
|
166
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
|
179
167
|
origin_count_records
|
180
168
|
end
|
181
169
|
end
|
@@ -5,7 +5,7 @@ module Bullet
|
|
5
5
|
def self.enable
|
6
6
|
require 'active_record'
|
7
7
|
::ActiveRecord::Base.class_eval do
|
8
|
-
class <<self
|
8
|
+
class << self
|
9
9
|
alias_method :origin_find, :find
|
10
10
|
def find(*args)
|
11
11
|
result = origin_find(*args)
|
@@ -45,9 +45,7 @@ module Bullet
|
|
45
45
|
|
46
46
|
::ActiveRecord::Persistence.class_eval do
|
47
47
|
def _create_record_with_bullet(*args)
|
48
|
-
_create_record_without_bullet(*args).tap
|
49
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
|
50
|
-
end
|
48
|
+
_create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
|
51
49
|
end
|
52
50
|
alias_method_chain :_create_record, :bullet
|
53
51
|
end
|
@@ -80,9 +78,7 @@ module Bullet
|
|
80
78
|
if Bullet.start?
|
81
79
|
records.compact!
|
82
80
|
if records.first.class.name !~ /^HABTM_/
|
83
|
-
records.each
|
84
|
-
Bullet::Detector::Association.add_object_associations(record, association)
|
85
|
-
end
|
81
|
+
records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
|
86
82
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
|
87
83
|
end
|
88
84
|
end
|
@@ -99,9 +95,7 @@ module Bullet
|
|
99
95
|
records = origin_find_with_associations
|
100
96
|
if Bullet.start?
|
101
97
|
associations = (eager_load_values + includes_values).uniq
|
102
|
-
records.each
|
103
|
-
Bullet::Detector::Association.add_object_associations(record, associations)
|
104
|
-
end
|
98
|
+
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
105
99
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
106
100
|
end
|
107
101
|
records
|
@@ -195,9 +189,7 @@ module Bullet
|
|
195
189
|
|
196
190
|
alias_method :origin_include?, :include?
|
197
191
|
def include?(object)
|
198
|
-
if Bullet.start?
|
199
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
200
|
-
end
|
192
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
201
193
|
origin_include?(object)
|
202
194
|
end
|
203
195
|
end
|
@@ -207,9 +199,11 @@ module Bullet
|
|
207
199
|
alias_method :origin_reader, :reader
|
208
200
|
def reader(force_reload = false)
|
209
201
|
result = origin_reader(force_reload)
|
202
|
+
|
210
203
|
if Bullet.start?
|
211
204
|
if @owner.class.name !~ /^HABTM_/ && !@inversed
|
212
205
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
206
|
+
|
213
207
|
if Bullet::Detector::NPlusOneQuery.impossible?(@owner)
|
214
208
|
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
215
209
|
else
|
@@ -234,9 +228,7 @@ module Bullet
|
|
234
228
|
alias_method :origin_count_records, :count_records
|
235
229
|
def count_records
|
236
230
|
result = has_cached_counter?
|
237
|
-
if Bullet.start? && !result
|
238
|
-
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
|
239
|
-
end
|
231
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
|
240
232
|
origin_count_records
|
241
233
|
end
|
242
234
|
end
|