bullet 4.14.4 → 5.0.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/.travis.yml +56 -1
- data/CHANGELOG.md +38 -2
- data/Gemfile.mongoid +0 -2
- data/Gemfile.mongoid-2.4 +0 -2
- data/Gemfile.mongoid-2.5 +0 -2
- data/Gemfile.mongoid-2.6 +0 -2
- data/Gemfile.mongoid-2.7 +0 -2
- data/Gemfile.mongoid-2.8 +0 -2
- data/Gemfile.mongoid-3.0 +0 -2
- data/Gemfile.mongoid-3.1 +0 -2
- data/Gemfile.mongoid-4.0 +0 -2
- data/Gemfile.mongoid-5.0 +17 -0
- data/Gemfile.rails-3.1 +0 -2
- data/Gemfile.rails-3.2 +0 -2
- data/Gemfile.rails-4.0 +0 -2
- data/Gemfile.rails-4.1 +0 -2
- data/Gemfile.rails-4.2 +0 -2
- data/Gemfile.rails-5.0 +17 -0
- data/README.md +29 -1
- data/bullet.gemspec +1 -1
- data/lib/bullet/active_record3.rb +65 -35
- data/lib/bullet/active_record3x.rb +54 -32
- data/lib/bullet/active_record4.rb +61 -31
- data/lib/bullet/active_record41.rb +63 -32
- data/lib/bullet/active_record42.rb +94 -49
- data/lib/bullet/active_record5.rb +217 -0
- data/lib/bullet/dependency.rb +16 -0
- data/lib/bullet/detector/association.rb +16 -16
- data/lib/bullet/detector/counter_cache.rb +13 -13
- data/lib/bullet/detector/n_plus_one_query.rb +33 -24
- data/lib/bullet/detector/unused_eager_loading.rb +1 -1
- data/lib/bullet/ext/object.rb +3 -1
- data/lib/bullet/mongoid5x.rb +56 -0
- data/lib/bullet/notification/n_plus_one_query.rb +6 -0
- data/lib/bullet/rack.rb +4 -6
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +28 -11
- data/spec/bullet/detector/counter_cache_spec.rb +8 -8
- data/spec/bullet/detector/n_plus_one_query_spec.rb +42 -27
- data/spec/bullet/ext/object_spec.rb +6 -0
- data/spec/bullet/notification/base_spec.rb +2 -2
- data/spec/bullet/rack_spec.rb +2 -2
- data/spec/bullet_spec.rb +47 -0
- data/spec/integration/active_record3/association_spec.rb +11 -2
- data/spec/integration/active_record4/association_spec.rb +32 -2
- data/spec/integration/active_record5/association_spec.rb +715 -0
- data/spec/integration/counter_cache_spec.rb +17 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/mongo_seed.rb +13 -0
- data/test.sh +1 -0
- data/update.sh +1 -0
- metadata +13 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5439116cdedcd96dfad6dfd315eaf47ee815153
|
|
4
|
+
data.tar.gz: 9542679b93fa670fbf8b014fb0cbd3adb13a30d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4704ead627526344ab065d5d0a9bd2f3516165f664d9ab97aca3dd576c55ecc75450636daceebe21d100562be45c5e9352296ea0cd5856b0a4205be2120751cb
|
|
7
|
+
data.tar.gz: 6b3d52be604e5188920592e6b3952d2a683364631739c097b619b151f9131b911454452eae824e13493a4866ff767eb9ba61da3a98097aa3042e498faf74bdd6
|
data/.travis.yml
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
sudo: false
|
|
1
2
|
language: ruby
|
|
2
3
|
rvm:
|
|
3
|
-
- 2.
|
|
4
|
+
- 2.0
|
|
5
|
+
- 2.1
|
|
6
|
+
- 2.2
|
|
7
|
+
- 2.2.3
|
|
4
8
|
gemfile:
|
|
9
|
+
- Gemfile.rails-5.0
|
|
5
10
|
- Gemfile.rails-4.2
|
|
6
11
|
- Gemfile.rails-4.1
|
|
7
12
|
- Gemfile.rails-4.0
|
|
8
13
|
- Gemfile.rails-3.2
|
|
9
14
|
- Gemfile.rails-3.1
|
|
10
15
|
- Gemfile.rails-3.0
|
|
16
|
+
- Gemfile.mongoid-5.0
|
|
17
|
+
- Gemfile.mongoid-4.0
|
|
11
18
|
- Gemfile.mongoid-3.1
|
|
12
19
|
- Gemfile.mongoid-3.0
|
|
13
20
|
- Gemfile.mongoid-2.8
|
|
@@ -19,3 +26,51 @@ env:
|
|
|
19
26
|
- DB=sqlite
|
|
20
27
|
services:
|
|
21
28
|
- mongodb
|
|
29
|
+
matrix:
|
|
30
|
+
exclude:
|
|
31
|
+
- rvm: 2.0
|
|
32
|
+
gemfile: Gemfile.rails-5.0
|
|
33
|
+
- rvm: 2.1
|
|
34
|
+
gemfile: Gemfile.rails-5.0
|
|
35
|
+
- rvm: 2.2
|
|
36
|
+
gemfile: Gemfile.rails-5.0
|
|
37
|
+
- rvm: 2.2
|
|
38
|
+
gemfile: Gemfile.rails-3.0
|
|
39
|
+
- rvm: 2.2
|
|
40
|
+
gemfile: Gemfile.rails-3.1
|
|
41
|
+
- rvm: 2.2
|
|
42
|
+
gemfile: Gemfile.rails-3.2
|
|
43
|
+
- rvm: 2.2
|
|
44
|
+
gemfile: Gemfile.mongoid-3.1
|
|
45
|
+
- rvm: 2.2
|
|
46
|
+
gemfile: Gemfile.mongoid-3.0
|
|
47
|
+
- rvm: 2.2
|
|
48
|
+
gemfile: Gemfile.mongoid-2.8
|
|
49
|
+
- rvm: 2.2
|
|
50
|
+
gemfile: Gemfile.mongoid-2.7
|
|
51
|
+
- rvm: 2.2
|
|
52
|
+
gemfile: Gemfile.mongoid-2.6
|
|
53
|
+
- rvm: 2.2
|
|
54
|
+
gemfile: Gemfile.mongoid-2.5
|
|
55
|
+
- rvm: 2.2
|
|
56
|
+
gemfile: Gemfile.mongoid-2.4
|
|
57
|
+
- rvm: 2.2.3
|
|
58
|
+
gemfile: Gemfile.rails-3.0
|
|
59
|
+
- rvm: 2.2.3
|
|
60
|
+
gemfile: Gemfile.rails-3.1
|
|
61
|
+
- rvm: 2.2.3
|
|
62
|
+
gemfile: Gemfile.rails-3.2
|
|
63
|
+
- rvm: 2.2.3
|
|
64
|
+
gemfile: Gemfile.mongoid-3.1
|
|
65
|
+
- rvm: 2.2.3
|
|
66
|
+
gemfile: Gemfile.mongoid-3.0
|
|
67
|
+
- rvm: 2.2.3
|
|
68
|
+
gemfile: Gemfile.mongoid-2.8
|
|
69
|
+
- rvm: 2.2.3
|
|
70
|
+
gemfile: Gemfile.mongoid-2.7
|
|
71
|
+
- rvm: 2.2.3
|
|
72
|
+
gemfile: Gemfile.mongoid-2.6
|
|
73
|
+
- rvm: 2.2.3
|
|
74
|
+
gemfile: Gemfile.mongoid-2.5
|
|
75
|
+
- rvm: 2.2.3
|
|
76
|
+
gemfile: Gemfile.mongoid-2.4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Next Release
|
|
2
2
|
|
|
3
|
+
## 5.0.0 (01/06/2015)
|
|
4
|
+
|
|
5
|
+
* Support Rails 5.0.0.beta1
|
|
6
|
+
|
|
7
|
+
## 4.14.10
|
|
8
|
+
|
|
9
|
+
* Fix `has_many :through` infinite loop issue
|
|
10
|
+
|
|
11
|
+
## 4.14.9
|
|
12
|
+
|
|
13
|
+
* Support mongoid 5.0.0
|
|
14
|
+
* Do not report association queries immediately after object creation to
|
|
15
|
+
require a preload
|
|
16
|
+
* Detect `counter_cache` for `has_many :through` association
|
|
17
|
+
|
|
18
|
+
## 4.14.8
|
|
19
|
+
|
|
20
|
+
* compatible with `composite_primary_keys` gem
|
|
21
|
+
|
|
22
|
+
## 4.14.7
|
|
23
|
+
|
|
24
|
+
* Fix AR 4.2 SingularAssociation#reader result can be nil
|
|
25
|
+
* `perform_out_of_channel_notifications` should always be triggered
|
|
26
|
+
|
|
27
|
+
## 4.14.6
|
|
28
|
+
|
|
29
|
+
* Fix false positive with `belongs_to` -> `belongs_to` for active\_record 4.2
|
|
30
|
+
* Activate active\_record hacks only when Bullet already start
|
|
31
|
+
|
|
32
|
+
## 4.14.5
|
|
33
|
+
|
|
34
|
+
* Don't execute query when running `to_sql`
|
|
35
|
+
* Send backtrace to `uniform_notifier`
|
|
36
|
+
* Fix sse response check
|
|
37
|
+
* Dynamically delegate available notifiers to UniformNotifier
|
|
38
|
+
|
|
3
39
|
## 4.14.4
|
|
4
40
|
|
|
5
41
|
* Fix false N + 1 warnings on Rails 4.2
|
|
@@ -10,11 +46,11 @@
|
|
|
10
46
|
|
|
11
47
|
## 4.14.2
|
|
12
48
|
|
|
13
|
-
* Hotfix nil object when add_impossible_object
|
|
49
|
+
* Hotfix nil object when `add_impossible_object`
|
|
14
50
|
|
|
15
51
|
## 4.14.1
|
|
16
52
|
|
|
17
|
-
* Fix has_one then has_many associations in rails 4.2
|
|
53
|
+
* Fix `has_one` then `has_many` associations in rails 4.2
|
|
18
54
|
* Append js and dom to html body in proper position
|
|
19
55
|
|
|
20
56
|
## 4.14.0 (10/03/2014)
|
data/Gemfile.mongoid
CHANGED
data/Gemfile.mongoid-2.4
CHANGED
data/Gemfile.mongoid-2.5
CHANGED
data/Gemfile.mongoid-2.6
CHANGED
data/Gemfile.mongoid-2.7
CHANGED
data/Gemfile.mongoid-2.8
CHANGED
data/Gemfile.mongoid-3.0
CHANGED
data/Gemfile.mongoid-3.1
CHANGED
data/Gemfile.mongoid-4.0
CHANGED
data/Gemfile.mongoid-5.0
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 4.0.0'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mongoid', '~> 5.0.0.beta', github: 'mongoid'
|
|
9
|
+
|
|
10
|
+
gem "rspec"
|
|
11
|
+
|
|
12
|
+
gem 'coveralls', require: false
|
|
13
|
+
|
|
14
|
+
platforms :rbx do
|
|
15
|
+
gem 'rubysl', '~> 2.0'
|
|
16
|
+
gem 'rubinius-developer_tools'
|
|
17
|
+
end
|
data/Gemfile.rails-3.1
CHANGED
data/Gemfile.rails-3.2
CHANGED
data/Gemfile.rails-4.0
CHANGED
data/Gemfile.rails-4.1
CHANGED
data/Gemfile.rails-4.2
CHANGED
data/Gemfile.rails-5.0
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '5.0.0.beta1'
|
|
6
|
+
gem 'sqlite3'
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'activerecord-import'
|
|
9
|
+
|
|
10
|
+
gem "rspec"
|
|
11
|
+
|
|
12
|
+
gem 'coveralls', require: false
|
|
13
|
+
|
|
14
|
+
platforms :rbx do
|
|
15
|
+
gem 'rubysl', '~> 2.0'
|
|
16
|
+
gem 'rubinius-developer_tools'
|
|
17
|
+
end
|
data/README.md
CHANGED
|
@@ -36,6 +36,9 @@ or add it into a Gemfile (Bundler):
|
|
|
36
36
|
gem "bullet", :group => "development"
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
**Note**: make sure `bullet` gem is added after activerecord (rails) and
|
|
40
|
+
mongoid.
|
|
41
|
+
|
|
39
42
|
## Configuration
|
|
40
43
|
|
|
41
44
|
Bullet won't do ANYTHING unless you tell it to explicitly. Append to
|
|
@@ -53,10 +56,14 @@ config.after_initialize do
|
|
|
53
56
|
:receiver => 'your_account@jabber.org',
|
|
54
57
|
:show_online_status => true }
|
|
55
58
|
Bullet.rails_logger = true
|
|
59
|
+
Bullet.honeybadger = true
|
|
56
60
|
Bullet.bugsnag = true
|
|
57
61
|
Bullet.airbrake = true
|
|
62
|
+
Bullet.rollbar = true
|
|
58
63
|
Bullet.add_footer = true
|
|
59
64
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
|
65
|
+
Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
|
|
66
|
+
Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
|
|
60
67
|
end
|
|
61
68
|
```
|
|
62
69
|
|
|
@@ -67,14 +74,18 @@ The code above will enable all seven of the Bullet notification systems:
|
|
|
67
74
|
* `Bullet.alert`: pop up a JavaScript alert in the browser
|
|
68
75
|
* `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
|
|
69
76
|
* `Bullet.rails_logger`: add warnings directly to the Rails log
|
|
77
|
+
* `Bullet.honeybadger`: add notifications to Honeybadger
|
|
70
78
|
* `Bullet.bugsnag`: add notifications to bugsnag
|
|
71
79
|
* `Bullet.airbrake`: add notifications to airbrake
|
|
80
|
+
* `Bullet.rollbar`: add notifications to rollbar
|
|
72
81
|
* `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
|
73
82
|
* `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
74
83
|
* `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
84
|
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
|
76
85
|
* `Bullet.add_footer`: adds the details in the bottom left corner of the page
|
|
77
86
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
|
87
|
+
* `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
|
|
88
|
+
* `Bullet.slack`: add notifications to slack
|
|
78
89
|
|
|
79
90
|
Bullet also allows you to disable any of its detectors.
|
|
80
91
|
|
|
@@ -103,6 +114,22 @@ Bullet.add_whitelist :type => :unused_eager_loading, :class_name => "Post", :ass
|
|
|
103
114
|
Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities
|
|
104
115
|
```
|
|
105
116
|
|
|
117
|
+
If you want to skip bullet in some specific controller actions, you can
|
|
118
|
+
do like
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
class ApplicationController < ActionController::Base
|
|
122
|
+
around_action :skip_bullet
|
|
123
|
+
|
|
124
|
+
def skip_bullet
|
|
125
|
+
Bullet.enable = false
|
|
126
|
+
yield
|
|
127
|
+
ensure
|
|
128
|
+
Bullet.enable = true
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
```
|
|
132
|
+
|
|
106
133
|
## Log
|
|
107
134
|
|
|
108
135
|
The Bullet log `log/bullet.log` will look something like this:
|
|
@@ -154,8 +181,9 @@ The Bullet gem uses rack middleware to profile requests. If you want to use Bull
|
|
|
154
181
|
```ruby
|
|
155
182
|
Bullet.profile do
|
|
156
183
|
# do anything
|
|
184
|
+
|
|
185
|
+
warnings = Bullet.warnings
|
|
157
186
|
end
|
|
158
|
-
warnings = Bullet.warnings
|
|
159
187
|
```
|
|
160
188
|
|
|
161
189
|
### Work with sinatra
|
data/bullet.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.required_rubygems_version = ">= 1.3.6"
|
|
19
19
|
|
|
20
20
|
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
|
21
|
-
s.add_runtime_dependency "uniform_notifier", "
|
|
21
|
+
s.add_runtime_dependency "uniform_notifier", "~> 1.9.0"
|
|
22
22
|
|
|
23
23
|
s.files = `git ls-files`.split("\n")
|
|
24
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module Bullet
|
|
2
2
|
module ActiveRecord
|
|
3
|
+
LOAD_TARGET = 'load_target'.freeze
|
|
4
|
+
|
|
3
5
|
def self.enable
|
|
4
6
|
require 'active_record'
|
|
5
7
|
::ActiveRecord::Relation.class_eval do
|
|
@@ -8,12 +10,14 @@ module Bullet
|
|
|
8
10
|
# if select only one object, then the only one object has impossible to cause N+1 query.
|
|
9
11
|
def to_a
|
|
10
12
|
records = origin_to_a
|
|
11
|
-
if
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if Bullet.start?
|
|
14
|
+
if records.size > 1
|
|
15
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
|
16
|
+
Bullet::Detector::CounterCache.add_possible_objects(records)
|
|
17
|
+
elsif records.size == 1
|
|
18
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
|
19
|
+
Bullet::Detector::CounterCache.add_impossible_object(records.first)
|
|
20
|
+
end
|
|
17
21
|
end
|
|
18
22
|
records
|
|
19
23
|
end
|
|
@@ -24,12 +28,14 @@ module Bullet
|
|
|
24
28
|
# include query for one to many associations.
|
|
25
29
|
# keep this eager loadings.
|
|
26
30
|
def preload_associations(records, associations, preload_options={})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
if Bullet.start?
|
|
32
|
+
records = [records].flatten.compact.uniq
|
|
33
|
+
return if records.empty?
|
|
34
|
+
records.each do |record|
|
|
35
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
36
|
+
end
|
|
37
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
31
38
|
end
|
|
32
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
33
39
|
origin_preload_associations(records, associations, preload_options={})
|
|
34
40
|
end
|
|
35
41
|
end
|
|
@@ -39,11 +45,13 @@ module Bullet
|
|
|
39
45
|
alias_method :origin_find_with_associations, :find_with_associations
|
|
40
46
|
def find_with_associations
|
|
41
47
|
records = origin_find_with_associations
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
if Bullet.start?
|
|
49
|
+
associations = (@eager_load_values + @includes_values).uniq
|
|
50
|
+
records.each do |record|
|
|
51
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
52
|
+
end
|
|
53
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
45
54
|
end
|
|
46
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
47
55
|
records
|
|
48
56
|
end
|
|
49
57
|
end
|
|
@@ -56,9 +64,11 @@ module Bullet
|
|
|
56
64
|
@bullet_eager_loadings = {}
|
|
57
65
|
records = origin_instantiate(rows)
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
if Bullet.start?
|
|
68
|
+
@bullet_eager_loadings.each do |klazz, eager_loadings_hash|
|
|
69
|
+
objects = eager_loadings_hash.keys
|
|
70
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
|
71
|
+
end
|
|
62
72
|
end
|
|
63
73
|
records
|
|
64
74
|
end
|
|
@@ -67,12 +77,14 @@ module Bullet
|
|
|
67
77
|
def construct_association(record, join, row)
|
|
68
78
|
result = origin_construct_association(record, join, row)
|
|
69
79
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
if Bullet.start?
|
|
81
|
+
associations = join.reflection.name
|
|
82
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
83
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
|
84
|
+
@bullet_eager_loadings[record.class] ||= {}
|
|
85
|
+
@bullet_eager_loadings[record.class][record] ||= Set.new
|
|
86
|
+
@bullet_eager_loadings[record.class][record] << associations
|
|
87
|
+
end
|
|
76
88
|
|
|
77
89
|
result
|
|
78
90
|
end
|
|
@@ -82,31 +94,41 @@ module Bullet
|
|
|
82
94
|
# call one to many associations
|
|
83
95
|
alias_method :origin_load_target, :load_target
|
|
84
96
|
def load_target
|
|
85
|
-
Bullet
|
|
97
|
+
if Bullet.start?
|
|
98
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
99
|
+
end
|
|
86
100
|
origin_load_target
|
|
87
101
|
end
|
|
88
102
|
|
|
89
103
|
alias_method :origin_first, :first
|
|
90
104
|
def first(*args)
|
|
91
|
-
Bullet
|
|
105
|
+
if Bullet.start?
|
|
106
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
107
|
+
end
|
|
92
108
|
origin_first(*args)
|
|
93
109
|
end
|
|
94
110
|
|
|
95
111
|
alias_method :origin_last, :last
|
|
96
112
|
def last(*args)
|
|
97
|
-
Bullet
|
|
113
|
+
if Bullet.start?
|
|
114
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
115
|
+
end
|
|
98
116
|
origin_last(*args)
|
|
99
117
|
end
|
|
100
118
|
|
|
101
119
|
alias_method :origin_empty?, :empty?
|
|
102
120
|
def empty?
|
|
103
|
-
Bullet
|
|
121
|
+
if Bullet.start?
|
|
122
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
123
|
+
end
|
|
104
124
|
origin_empty?
|
|
105
125
|
end
|
|
106
126
|
|
|
107
127
|
alias_method :origin_include?, :include?
|
|
108
128
|
def include?(object)
|
|
109
|
-
Bullet
|
|
129
|
+
if Bullet.start?
|
|
130
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
131
|
+
end
|
|
110
132
|
origin_include?(object)
|
|
111
133
|
end
|
|
112
134
|
end
|
|
@@ -117,15 +139,19 @@ module Bullet
|
|
|
117
139
|
def load_target
|
|
118
140
|
# avoid stack level too deep
|
|
119
141
|
result = origin_load_target
|
|
120
|
-
Bullet
|
|
121
|
-
|
|
142
|
+
if Bullet.start?
|
|
143
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?(LOAD_TARGET) }
|
|
144
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
|
145
|
+
end
|
|
122
146
|
result
|
|
123
147
|
end
|
|
124
148
|
|
|
125
149
|
alias_method :origin_set_inverse_instance, :set_inverse_instance
|
|
126
150
|
def set_inverse_instance(record, instance)
|
|
127
|
-
if
|
|
128
|
-
|
|
151
|
+
if Bullet.start?
|
|
152
|
+
if record && we_can_set_the_inverse_on_this?(record)
|
|
153
|
+
Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
|
|
154
|
+
end
|
|
129
155
|
end
|
|
130
156
|
origin_set_inverse_instance(record, instance)
|
|
131
157
|
end
|
|
@@ -136,7 +162,9 @@ module Bullet
|
|
|
136
162
|
|
|
137
163
|
def has_cached_counter?
|
|
138
164
|
result = origin_has_cached_counter?
|
|
139
|
-
Bullet
|
|
165
|
+
if Bullet.start? && !result
|
|
166
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
|
|
167
|
+
end
|
|
140
168
|
result
|
|
141
169
|
end
|
|
142
170
|
end
|
|
@@ -145,7 +173,9 @@ module Bullet
|
|
|
145
173
|
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
|
146
174
|
def has_cached_counter?
|
|
147
175
|
result = origin_has_cached_counter?
|
|
148
|
-
Bullet
|
|
176
|
+
if Bullet.start? && !result
|
|
177
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
|
|
178
|
+
end
|
|
149
179
|
result
|
|
150
180
|
end
|
|
151
181
|
end
|