bullet 5.4.3 → 5.6.0
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/.gitignore +1 -0
- data/.travis.yml +1 -96
- data/CHANGELOG.md +13 -7
- data/Gemfile +6 -1
- data/Gemfile.mongoid-5.0 +1 -1
- data/{Gemfile.mongoid-2.4 → Gemfile.mongoid-6.0} +2 -2
- data/Gemfile.rails-5.0 +1 -1
- data/{Gemfile.mongoid-2.5 → Gemfile.rails-5.1} +3 -3
- data/Hacking.md +1 -1
- data/README.md +14 -20
- data/lib/bullet/active_record4.rb +2 -2
- data/lib/bullet/active_record41.rb +5 -6
- data/lib/bullet/active_record42.rb +6 -19
- data/lib/bullet/active_record5.rb +44 -62
- data/lib/bullet/dependency.rb +8 -34
- data/lib/bullet/detector/association.rb +2 -2
- data/lib/bullet/detector/n_plus_one_query.rb +6 -5
- data/lib/bullet/ext/object.rb +1 -1
- data/lib/bullet/ext/string.rb +1 -1
- data/lib/bullet/{mongoid3x.rb → mongoid6x.rb} +3 -3
- data/lib/bullet/notification/base.rb +1 -1
- data/lib/bullet/notification/n_plus_one_query.rb +3 -3
- data/lib/bullet/notification/unused_eager_loading.rb +12 -7
- data/lib/bullet/rack.rb +7 -2
- data/lib/bullet/stack_trace_filter.rb +2 -1
- data/lib/bullet/version.rb +1 -1
- data/lib/generators/bullet/install_generator.rb +46 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +11 -11
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +1 -1
- data/spec/integration/{active_record4 → active_record}/association_spec.rb +1 -1
- data/spec/integration/counter_cache_spec.rb +7 -0
- data/spec/support/mongo_seed.rb +2 -10
- data/test.sh +1 -10
- data/update.sh +1 -10
- metadata +9 -23
- data/Gemfile.mongoid-2.6 +0 -15
- data/Gemfile.mongoid-2.7 +0 -15
- data/Gemfile.mongoid-2.8 +0 -15
- data/Gemfile.mongoid-3.0 +0 -15
- data/Gemfile.mongoid-3.1 +0 -15
- data/Gemfile.rails-3.0 +0 -16
- data/Gemfile.rails-3.1 +0 -16
- data/Gemfile.rails-3.2 +0 -16
- data/lib/bullet/active_record3.rb +0 -238
- data/lib/bullet/active_record3x.rb +0 -210
- data/lib/bullet/mongoid2x.rb +0 -56
- data/spec/integration/active_record3/association_spec.rb +0 -745
- data/spec/integration/active_record5/association_spec.rb +0 -768
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 652f59b5a91224c16cace3931e368d0da02fa449
|
|
4
|
+
data.tar.gz: 9ef371969315cd308b194a9d230d1f19892a57e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed473ab951e1f168de703cf0615f203abc93e37ef896330d6f91c7b61d320cd0906e691e41245e13a11aa9e3aa3d059ea62b00b256fa96af0540c8ab35ebc2fb
|
|
7
|
+
data.tar.gz: f6c4456dfb56957b441fce1b56094baacc911186b59b48b43f22e41ad3bbed88c52aa16b4bc7247b7ca37a3c7d026bb45f5342ccc24b37bc47836cd63fb41a1c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -1,107 +1,12 @@
|
|
|
1
1
|
sudo: false
|
|
2
2
|
language: ruby
|
|
3
3
|
rvm:
|
|
4
|
-
- 1.9.3
|
|
5
|
-
- 2.0
|
|
6
|
-
- 2.1
|
|
7
|
-
- 2.2
|
|
8
4
|
- 2.3.0
|
|
9
5
|
gemfile:
|
|
6
|
+
- Gemfile.rails-5.1
|
|
10
7
|
- Gemfile.rails-5.0
|
|
11
8
|
- Gemfile.rails-4.2
|
|
12
9
|
- Gemfile.rails-4.1
|
|
13
10
|
- Gemfile.rails-4.0
|
|
14
|
-
- Gemfile.rails-3.2
|
|
15
|
-
- Gemfile.rails-3.1
|
|
16
|
-
- Gemfile.rails-3.0
|
|
17
|
-
- Gemfile.mongoid-5.0
|
|
18
|
-
- Gemfile.mongoid-4.0
|
|
19
|
-
- Gemfile.mongoid-3.1
|
|
20
|
-
- Gemfile.mongoid-3.0
|
|
21
|
-
- Gemfile.mongoid-2.8
|
|
22
|
-
- Gemfile.mongoid-2.7
|
|
23
|
-
- Gemfile.mongoid-2.6
|
|
24
|
-
- Gemfile.mongoid-2.5
|
|
25
|
-
- Gemfile.mongoid-2.4
|
|
26
11
|
env:
|
|
27
12
|
- DB=sqlite
|
|
28
|
-
services:
|
|
29
|
-
- mongodb
|
|
30
|
-
matrix:
|
|
31
|
-
exclude:
|
|
32
|
-
- rvm: 1.9.3
|
|
33
|
-
gemfile: Gemfile.rails-4.0
|
|
34
|
-
- rvm: 1.9.3
|
|
35
|
-
gemfile: Gemfile.rails-4.1
|
|
36
|
-
- rvm: 1.9.3
|
|
37
|
-
gemfile: Gemfile.rails-4.2
|
|
38
|
-
- rvm: 1.9.3
|
|
39
|
-
gemfile: Gemfile.rails-5.0
|
|
40
|
-
- rvm: 1.9.3
|
|
41
|
-
gemfile: Gemfile.mongoid-2.4
|
|
42
|
-
- rvm: 1.9.3
|
|
43
|
-
gemfile: Gemfile.mongoid-2.5
|
|
44
|
-
- rvm: 1.9.3
|
|
45
|
-
gemfile: Gemfile.mongoid-2.6
|
|
46
|
-
- rvm: 1.9.3
|
|
47
|
-
gemfile: Gemfile.mongoid-2.7
|
|
48
|
-
- rvm: 1.9.3
|
|
49
|
-
gemfile: Gemfile.mongoid-2.8
|
|
50
|
-
- rvm: 1.9.3
|
|
51
|
-
gemfile: Gemfile.mongoid-3.0
|
|
52
|
-
- rvm: 1.9.3
|
|
53
|
-
gemfile: Gemfile.mongoid-3.1
|
|
54
|
-
- rvm: 1.9.3
|
|
55
|
-
gemfile: Gemfile.mongoid-4.0
|
|
56
|
-
- rvm: 1.9.3
|
|
57
|
-
gemfile: Gemfile.mongoid-5.0
|
|
58
|
-
- rvm: 2.0
|
|
59
|
-
gemfile: Gemfile.rails-3.0
|
|
60
|
-
- rvm: 2.0
|
|
61
|
-
gemfile: Gemfile.rails-5.0
|
|
62
|
-
- rvm: 2.1
|
|
63
|
-
gemfile: Gemfile.rails-3.0
|
|
64
|
-
- rvm: 2.1
|
|
65
|
-
gemfile: Gemfile.rails-5.0
|
|
66
|
-
- rvm: 2.2
|
|
67
|
-
gemfile: Gemfile.rails-3.0
|
|
68
|
-
- rvm: 2.2
|
|
69
|
-
gemfile: Gemfile.rails-3.1
|
|
70
|
-
- rvm: 2.2
|
|
71
|
-
gemfile: Gemfile.rails-3.2
|
|
72
|
-
- rvm: 2.2
|
|
73
|
-
gemfile: Gemfile.rails-5.0
|
|
74
|
-
- rvm: 2.2
|
|
75
|
-
gemfile: Gemfile.mongoid-3.1
|
|
76
|
-
- rvm: 2.2
|
|
77
|
-
gemfile: Gemfile.mongoid-3.0
|
|
78
|
-
- rvm: 2.2
|
|
79
|
-
gemfile: Gemfile.mongoid-2.8
|
|
80
|
-
- rvm: 2.2
|
|
81
|
-
gemfile: Gemfile.mongoid-2.7
|
|
82
|
-
- rvm: 2.2
|
|
83
|
-
gemfile: Gemfile.mongoid-2.6
|
|
84
|
-
- rvm: 2.2
|
|
85
|
-
gemfile: Gemfile.mongoid-2.5
|
|
86
|
-
- rvm: 2.2
|
|
87
|
-
gemfile: Gemfile.mongoid-2.4
|
|
88
|
-
- rvm: 2.3.0
|
|
89
|
-
gemfile: Gemfile.rails-3.0
|
|
90
|
-
- rvm: 2.3.0
|
|
91
|
-
gemfile: Gemfile.rails-3.1
|
|
92
|
-
- rvm: 2.3.0
|
|
93
|
-
gemfile: Gemfile.rails-3.2
|
|
94
|
-
- rvm: 2.3.0
|
|
95
|
-
gemfile: Gemfile.mongoid-3.1
|
|
96
|
-
- rvm: 2.3.0
|
|
97
|
-
gemfile: Gemfile.mongoid-3.0
|
|
98
|
-
- rvm: 2.3.0
|
|
99
|
-
gemfile: Gemfile.mongoid-2.8
|
|
100
|
-
- rvm: 2.3.0
|
|
101
|
-
gemfile: Gemfile.mongoid-2.7
|
|
102
|
-
- rvm: 2.3.0
|
|
103
|
-
gemfile: Gemfile.mongoid-2.6
|
|
104
|
-
- rvm: 2.3.0
|
|
105
|
-
gemfile: Gemfile.mongoid-2.5
|
|
106
|
-
- rvm: 2.3.0
|
|
107
|
-
gemfile: Gemfile.mongoid-2.4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
# Next Release
|
|
2
2
|
|
|
3
|
-
## 5.
|
|
3
|
+
## 5.6.0 (07/16/2017)
|
|
4
4
|
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
* Migrate alias_method to Module#prepend
|
|
6
|
+
* Add install generator
|
|
7
|
+
* Stack trace filter
|
|
8
|
+
* Fix rails 5.1 compatibility
|
|
9
|
+
* Fix inverse_of for rails 5
|
|
10
|
+
* Fix detect file attachment for rack #319
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## 5.4.1
|
|
12
|
+
## 5.5.0 (12/30/2016)
|
|
12
13
|
|
|
13
14
|
* Display http request method #311
|
|
15
|
+
* Add close button to footer
|
|
14
16
|
* Raise an error if bullet does not support AR or Mongoid
|
|
17
|
+
* Avoid double backtrace
|
|
18
|
+
* Fix false alert on counter cache when associations are already loaded #288
|
|
19
|
+
* Fix "false alert" in rails 5 #239
|
|
20
|
+
* Do not support ActiveRecord 3.x and Mongoid 3.x / 4.x anymore
|
|
15
21
|
|
|
16
22
|
## 5.4.0 (10/09/2016)
|
|
17
23
|
|
data/Gemfile
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
+
git_source(:github) do |repo_name|
|
|
4
|
+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
|
|
5
|
+
"https://github.com/#{repo_name}.git"
|
|
6
|
+
end
|
|
7
|
+
|
|
3
8
|
gemspec
|
|
4
9
|
|
|
5
|
-
gem 'rails', github: 'rails
|
|
10
|
+
gem 'rails', github: 'rails'
|
|
6
11
|
gem 'sqlite3', platforms: [:ruby]
|
|
7
12
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
13
|
gem 'activerecord-import'
|
data/Gemfile.mongoid-5.0
CHANGED
|
@@ -2,10 +2,10 @@ source "https://rubygems.org"
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
gem 'rails', '~>
|
|
5
|
+
gem 'rails', '~> 5.0.0'
|
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
-
gem 'mongoid', '~>
|
|
8
|
+
gem 'mongoid', '~> 6.0.0'
|
|
9
9
|
|
|
10
10
|
gem "rspec"
|
|
11
11
|
|
data/Gemfile.rails-5.0
CHANGED
|
@@ -2,10 +2,10 @@ source "https://rubygems.org"
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
gem 'rails', '~>
|
|
6
|
-
gem 'sqlite3'
|
|
5
|
+
gem 'rails', '~> 5.1.0'
|
|
6
|
+
gem 'sqlite3'
|
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
-
gem '
|
|
8
|
+
gem 'activerecord-import'
|
|
9
9
|
|
|
10
10
|
gem "rspec"
|
|
11
11
|
|
data/Hacking.md
CHANGED
|
@@ -28,7 +28,7 @@ So the flow of a request goes like this:
|
|
|
28
28
|
the notification collector
|
|
29
29
|
2. The request is handled by Rails, and the installed ActiveRecord extensions
|
|
30
30
|
trigger Detector callbacks
|
|
31
|
-
3. Detectors once called, will determine whether something noteworthy
|
|
31
|
+
3. Detectors once called, will determine whether something noteworthy happened.
|
|
32
32
|
If yes, then a Notification is created and stored in the notification collector.
|
|
33
33
|
4. Rails finishes handling the request
|
|
34
34
|
5. For each notification in the collector, Bullet will iterate over each
|
data/README.md
CHANGED
|
@@ -9,10 +9,12 @@ The Bullet gem is designed to help you increase your application's performance b
|
|
|
9
9
|
|
|
10
10
|
Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
|
|
11
11
|
|
|
12
|
-
Bullet gem now supports **activerecord** >=
|
|
12
|
+
Bullet gem now supports **activerecord** >= 4.0 and **mongoid** >= 4.0.
|
|
13
13
|
|
|
14
14
|
If you use activerecord 2.x, please use bullet <= 4.5.0
|
|
15
15
|
|
|
16
|
+
If you use activerecord 3.x, please use bullet < 5.5.0
|
|
17
|
+
|
|
16
18
|
## External Introduction
|
|
17
19
|
|
|
18
20
|
* [http://railscasts.com/episodes/372-bullet](http://railscasts.com/episodes/372-bullet)
|
|
@@ -32,7 +34,7 @@ or add it into a Gemfile (Bundler):
|
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
```ruby
|
|
35
|
-
gem
|
|
37
|
+
gem 'bullet', group: 'development'
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
**Note**: make sure `bullet` gem is added after activerecord (rails) and
|
|
@@ -68,23 +70,24 @@ end
|
|
|
68
70
|
|
|
69
71
|
The notifier of Bullet is a wrap of [uniform_notifier](https://github.com/flyerhzm/uniform_notifier)
|
|
70
72
|
|
|
71
|
-
The code above will enable all
|
|
73
|
+
The code above will enable all of the Bullet notification systems:
|
|
72
74
|
* `Bullet.enable`: enable Bullet gem, otherwise do nothing
|
|
73
75
|
* `Bullet.alert`: pop up a JavaScript alert in the browser
|
|
74
76
|
* `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
|
|
77
|
+
* `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
|
78
|
+
* `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
79
|
+
* `Bullet.xmpp`: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the Bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the Bullet account won't announce it's online status anymore.
|
|
75
80
|
* `Bullet.rails_logger`: add warnings directly to the Rails log
|
|
76
81
|
* `Bullet.honeybadger`: add notifications to Honeybadger
|
|
77
82
|
* `Bullet.bugsnag`: add notifications to bugsnag
|
|
78
83
|
* `Bullet.airbrake`: add notifications to airbrake
|
|
79
84
|
* `Bullet.rollbar`: add notifications to rollbar
|
|
80
|
-
* `Bullet.
|
|
81
|
-
* `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
82
|
-
* `Bullet.xmpp`: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the Bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the Bullet account won't announce it's online status anymore.
|
|
83
|
-
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
|
84
|
-
* `Bullet.add_footer`: adds the details in the bottom left corner of the page
|
|
85
|
+
* `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.
|
|
85
86
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
|
86
87
|
* `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
|
|
87
88
|
* `Bullet.slack`: add notifications to slack
|
|
89
|
+
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
|
90
|
+
|
|
88
91
|
|
|
89
92
|
Bullet also allows you to disable any of its detectors.
|
|
90
93
|
|
|
@@ -300,19 +303,10 @@ And run
|
|
|
300
303
|
bundle install
|
|
301
304
|
```
|
|
302
305
|
|
|
303
|
-
6\. enable the Bullet gem
|
|
304
|
-
`config/environments/development.rb`
|
|
306
|
+
6\. enable the Bullet gem with generate command
|
|
305
307
|
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
Bullet.enable = true
|
|
309
|
-
Bullet.alert = true
|
|
310
|
-
Bullet.bullet_logger = true
|
|
311
|
-
Bullet.console = true
|
|
312
|
-
# Bullet.growl = true
|
|
313
|
-
Bullet.rails_logger = true
|
|
314
|
-
Bullet.add_footer = true
|
|
315
|
-
end
|
|
308
|
+
```
|
|
309
|
+
bundle exec rails g bullet:install
|
|
316
310
|
```
|
|
317
311
|
|
|
318
312
|
7\. Start the server
|
|
@@ -152,7 +152,7 @@ module Bullet
|
|
|
152
152
|
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
153
153
|
alias_method :origin_empty?, :empty?
|
|
154
154
|
def empty?
|
|
155
|
-
if Bullet.start? && !has_cached_counter?(@reflection)
|
|
155
|
+
if Bullet.start? && !loaded? && !has_cached_counter?(@reflection)
|
|
156
156
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
157
157
|
end
|
|
158
158
|
origin_empty?
|
|
@@ -162,7 +162,7 @@ module Bullet
|
|
|
162
162
|
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
|
163
163
|
alias_method :origin_empty?, :empty?
|
|
164
164
|
def empty?
|
|
165
|
-
if Bullet.start?
|
|
165
|
+
if Bullet.start? && !loaded?
|
|
166
166
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
167
167
|
end
|
|
168
168
|
origin_empty?
|
|
@@ -176,14 +176,13 @@ module Bullet
|
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
179
|
-
alias_method :
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
result = origin_has_cached_counter?(reflection)
|
|
179
|
+
alias_method :origin_count_records, :count_records
|
|
180
|
+
def count_records
|
|
181
|
+
result = has_cached_counter?
|
|
183
182
|
if Bullet.start? && !result
|
|
184
|
-
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
|
|
183
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
|
|
185
184
|
end
|
|
186
|
-
|
|
185
|
+
origin_count_records
|
|
187
186
|
end
|
|
188
187
|
end
|
|
189
188
|
end
|
|
@@ -230,33 +230,20 @@ module Bullet
|
|
|
230
230
|
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
231
231
|
alias_method :origin_many_empty?, :empty?
|
|
232
232
|
def empty?
|
|
233
|
-
Thread.current[:bullet_collection_empty] = true
|
|
234
233
|
result = origin_many_empty?
|
|
235
|
-
Thread.current[:bullet_collection_empty] = nil
|
|
236
234
|
if Bullet.start? && !has_cached_counter?(@reflection)
|
|
237
235
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
238
236
|
end
|
|
239
237
|
result
|
|
240
238
|
end
|
|
241
239
|
|
|
242
|
-
alias_method :
|
|
243
|
-
def
|
|
244
|
-
result =
|
|
245
|
-
if Bullet.start? && !result
|
|
246
|
-
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
|
|
240
|
+
alias_method :origin_count_records, :count_records
|
|
241
|
+
def count_records
|
|
242
|
+
result = has_cached_counter?
|
|
243
|
+
if Bullet.start? && !result
|
|
244
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
|
|
247
245
|
end
|
|
248
|
-
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
::ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
|
|
253
|
-
alias_method :origin_hmt_has_cached_counter?, :has_cached_counter?
|
|
254
|
-
def has_cached_counter?(reflection = reflection())
|
|
255
|
-
result = origin_hmt_has_cached_counter?(reflection)
|
|
256
|
-
if Bullet.start? && !result && !Thread.current[:bullet_collection_empty]
|
|
257
|
-
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
|
|
258
|
-
end
|
|
259
|
-
result
|
|
246
|
+
origin_count_records
|
|
260
247
|
end
|
|
261
248
|
end
|
|
262
249
|
end
|
|
@@ -18,38 +18,34 @@ module Bullet
|
|
|
18
18
|
module ActiveRecord
|
|
19
19
|
def self.enable
|
|
20
20
|
require 'active_record'
|
|
21
|
-
::ActiveRecord::Base.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
result
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(result.first)
|
|
33
|
-
Bullet::Detector::CounterCache.add_impossible_object(result.first)
|
|
34
|
-
end
|
|
35
|
-
elsif result.is_a? ::ActiveRecord::Base
|
|
36
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
|
37
|
-
Bullet::Detector::CounterCache.add_impossible_object(result)
|
|
21
|
+
::ActiveRecord::Base.extend(Module.new {
|
|
22
|
+
def find_by_sql(sql, binds = [], preparable: nil, &block)
|
|
23
|
+
result = super
|
|
24
|
+
if Bullet.start?
|
|
25
|
+
if result.is_a? Array
|
|
26
|
+
if result.size > 1
|
|
27
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
|
28
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
|
29
|
+
elsif result.size == 1
|
|
30
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result.first)
|
|
31
|
+
Bullet::Detector::CounterCache.add_impossible_object(result.first)
|
|
38
32
|
end
|
|
33
|
+
elsif result.is_a? ::ActiveRecord::Base
|
|
34
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
|
35
|
+
Bullet::Detector::CounterCache.add_impossible_object(result)
|
|
39
36
|
end
|
|
40
|
-
result
|
|
41
37
|
end
|
|
38
|
+
result
|
|
42
39
|
end
|
|
43
|
-
|
|
40
|
+
})
|
|
44
41
|
|
|
45
42
|
::ActiveRecord::Base.prepend(SaveWithBulletSupport)
|
|
46
43
|
|
|
47
|
-
::ActiveRecord::Relation.
|
|
48
|
-
alias_method :origin_records, :records
|
|
44
|
+
::ActiveRecord::Relation.prepend(Module.new {
|
|
49
45
|
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
|
50
46
|
# if select only one object, then the only one object has impossible to cause N+1 query.
|
|
51
47
|
def records
|
|
52
|
-
result =
|
|
48
|
+
result = super
|
|
53
49
|
if Bullet.start?
|
|
54
50
|
if result.first.class.name !~ /^HABTM_/
|
|
55
51
|
if result.size > 1
|
|
@@ -63,11 +59,9 @@ module Bullet
|
|
|
63
59
|
end
|
|
64
60
|
result
|
|
65
61
|
end
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
::ActiveRecord::Associations::Preloader.class_eval do
|
|
69
|
-
alias_method :origin_preloaders_for_one, :preloaders_for_one
|
|
62
|
+
})
|
|
70
63
|
|
|
64
|
+
::ActiveRecord::Associations::Preloader.prepend(Module.new {
|
|
71
65
|
def preloaders_for_one(association, records, scope)
|
|
72
66
|
if Bullet.start?
|
|
73
67
|
records.compact!
|
|
@@ -78,16 +72,15 @@ module Bullet
|
|
|
78
72
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
|
|
79
73
|
end
|
|
80
74
|
end
|
|
81
|
-
|
|
75
|
+
super
|
|
82
76
|
end
|
|
83
|
-
|
|
77
|
+
})
|
|
84
78
|
|
|
85
|
-
::ActiveRecord::FinderMethods.
|
|
79
|
+
::ActiveRecord::FinderMethods.prepend(Module.new {
|
|
86
80
|
# add includes in scope
|
|
87
|
-
alias_method :origin_find_with_associations, :find_with_associations
|
|
88
81
|
def find_with_associations
|
|
89
|
-
return
|
|
90
|
-
records =
|
|
82
|
+
return super { |r| yield r } if block_given?
|
|
83
|
+
records = super
|
|
91
84
|
if Bullet.start?
|
|
92
85
|
associations = (eager_load_values + includes_values).uniq
|
|
93
86
|
records.each do |record|
|
|
@@ -97,16 +90,12 @@ module Bullet
|
|
|
97
90
|
end
|
|
98
91
|
records
|
|
99
92
|
end
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
::ActiveRecord::Associations::JoinDependency.class_eval do
|
|
103
|
-
alias_method :origin_instantiate, :instantiate
|
|
104
|
-
alias_method :origin_construct, :construct
|
|
105
|
-
alias_method :origin_construct_model, :construct_model
|
|
93
|
+
})
|
|
106
94
|
|
|
95
|
+
::ActiveRecord::Associations::JoinDependency.prepend(Module.new {
|
|
107
96
|
def instantiate(result_set, aliases)
|
|
108
97
|
@bullet_eager_loadings = {}
|
|
109
|
-
records =
|
|
98
|
+
records = super
|
|
110
99
|
|
|
111
100
|
if Bullet.start?
|
|
112
101
|
@bullet_eager_loadings.each do |klazz, eager_loadings_hash|
|
|
@@ -135,12 +124,12 @@ module Bullet
|
|
|
135
124
|
end
|
|
136
125
|
end
|
|
137
126
|
|
|
138
|
-
|
|
127
|
+
super
|
|
139
128
|
end
|
|
140
129
|
|
|
141
130
|
# call join associations
|
|
142
131
|
def construct_model(record, node, row, model_cache, id, aliases)
|
|
143
|
-
result =
|
|
132
|
+
result = super
|
|
144
133
|
|
|
145
134
|
if Bullet.start?
|
|
146
135
|
associations = node.reflection.name
|
|
@@ -153,13 +142,11 @@ module Bullet
|
|
|
153
142
|
|
|
154
143
|
result
|
|
155
144
|
end
|
|
156
|
-
|
|
145
|
+
})
|
|
157
146
|
|
|
158
|
-
::ActiveRecord::Associations::CollectionAssociation.
|
|
159
|
-
# call one to many associations
|
|
160
|
-
alias_method :origin_load_target, :load_target
|
|
147
|
+
::ActiveRecord::Associations::CollectionAssociation.prepend(Module.new {
|
|
161
148
|
def load_target
|
|
162
|
-
records =
|
|
149
|
+
records = super
|
|
163
150
|
|
|
164
151
|
if Bullet.start?
|
|
165
152
|
if self.is_a? ::ActiveRecord::Associations::ThroughAssociation
|
|
@@ -183,28 +170,25 @@ module Bullet
|
|
|
183
170
|
records
|
|
184
171
|
end
|
|
185
172
|
|
|
186
|
-
alias_method :origin_empty?, :empty?
|
|
187
173
|
def empty?
|
|
188
174
|
if Bullet.start? && !reflection.has_cached_counter?
|
|
189
175
|
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
190
176
|
end
|
|
191
|
-
|
|
177
|
+
super
|
|
192
178
|
end
|
|
193
179
|
|
|
194
|
-
alias_method :origin_include?, :include?
|
|
195
180
|
def include?(object)
|
|
196
181
|
if Bullet.start?
|
|
197
182
|
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
198
183
|
end
|
|
199
|
-
|
|
184
|
+
super
|
|
200
185
|
end
|
|
201
|
-
|
|
186
|
+
})
|
|
202
187
|
|
|
203
|
-
::ActiveRecord::Associations::SingularAssociation.
|
|
188
|
+
::ActiveRecord::Associations::SingularAssociation.prepend(Module.new {
|
|
204
189
|
# call has_one and belongs_to associations
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
result = origin_reader(force_reload)
|
|
190
|
+
def target
|
|
191
|
+
result = super()
|
|
208
192
|
if Bullet.start?
|
|
209
193
|
if owner.class.name !~ /^HABTM_/ && !@inversed
|
|
210
194
|
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
@@ -217,27 +201,25 @@ module Bullet
|
|
|
217
201
|
end
|
|
218
202
|
result
|
|
219
203
|
end
|
|
220
|
-
|
|
204
|
+
})
|
|
221
205
|
|
|
222
|
-
::ActiveRecord::Associations::HasManyAssociation.
|
|
223
|
-
alias_method :origin_many_empty?, :empty?
|
|
206
|
+
::ActiveRecord::Associations::HasManyAssociation.prepend(Module.new {
|
|
224
207
|
def empty?
|
|
225
|
-
result =
|
|
208
|
+
result = super
|
|
226
209
|
if Bullet.start? && !reflection.has_cached_counter?
|
|
227
210
|
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
|
228
211
|
end
|
|
229
212
|
result
|
|
230
213
|
end
|
|
231
214
|
|
|
232
|
-
alias_method :origin_count_records, :count_records
|
|
233
215
|
def count_records
|
|
234
216
|
result = reflection.has_cached_counter?
|
|
235
217
|
if Bullet.start? && !result && !self.is_a?(::ActiveRecord::Associations::ThroughAssociation)
|
|
236
218
|
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
|
|
237
219
|
end
|
|
238
|
-
|
|
220
|
+
super
|
|
239
221
|
end
|
|
240
|
-
|
|
222
|
+
})
|
|
241
223
|
end
|
|
242
224
|
end
|
|
243
225
|
end
|