bullet 4.14.4 → 4.14.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbb4f34774c895c76a37a414109e24ca1217a2a5
4
- data.tar.gz: bb7632755a33243163cfccd5285fd305c74adac0
3
+ metadata.gz: 6f638b646b9513031fb22f2e225286902ca056d5
4
+ data.tar.gz: f9144079dd390c7f7c3bb5f584b9b7f5c9552ec7
5
5
  SHA512:
6
- metadata.gz: 3e09a8384a358f7db6f3fee7b94a613af8f08ee0e4079394a595f794737f8b397e80c3ac76f0808e8d1c3993e14c97a65162497baad8652b130f76d69646b55c
7
- data.tar.gz: 904ed8a5c66a7d2d9479f0e4d82246d0f1f818548bbcfc33bc13eaf4b8e42dc2ce75fb4481741c9ae5597fcb6f84528b1671eb9bfe46be8985d20a9f2917acd2
6
+ metadata.gz: 646ba3c219617f31c8e0b2e0f31b106c9a6a17db3029241e1b0bd53341532d9982e4c8e01ffbba5094423edf337e86e56b45b923b9000ba151fd5370bcfbc8b7
7
+ data.tar.gz: 9a75eb39b6bd37f8f14d343e90aea52ac7438771755374799f423890f7181454c3cc10c0bd0502c577be62e38ad2193867934a4fd36837d411ffe40077de562e
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.2
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
4
6
  gemfile:
5
7
  - Gemfile.rails-4.2
6
8
  - Gemfile.rails-4.1
@@ -8,6 +10,7 @@ gemfile:
8
10
  - Gemfile.rails-3.2
9
11
  - Gemfile.rails-3.1
10
12
  - Gemfile.rails-3.0
13
+ - Gemfile.mongoid-4.0
11
14
  - Gemfile.mongoid-3.1
12
15
  - Gemfile.mongoid-3.0
13
16
  - Gemfile.mongoid-2.8
@@ -19,3 +22,25 @@ env:
19
22
  - DB=sqlite
20
23
  services:
21
24
  - mongodb
25
+ matrix:
26
+ exclude:
27
+ - rvm: 2.2
28
+ gemfile: Gemfile.rails-3.0
29
+ - rvm: 2.2
30
+ gemfile: Gemfile.rails-3.1
31
+ - rvm: 2.2
32
+ gemfile: Gemfile.rails-3.2
33
+ - rvm: 2.2
34
+ gemfile: Gemfile.mongoid-3.1
35
+ - rvm: 2.2
36
+ gemfile: Gemfile.mongoid-3.0
37
+ - rvm: 2.2
38
+ gemfile: Gemfile.mongoid-2.8
39
+ - rvm: 2.2
40
+ gemfile: Gemfile.mongoid-2.7
41
+ - rvm: 2.2
42
+ gemfile: Gemfile.mongoid-2.6
43
+ - rvm: 2.2
44
+ gemfile: Gemfile.mongoid-2.5
45
+ - rvm: 2.2
46
+ gemfile: Gemfile.mongoid-2.4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.14.6
4
+
5
+ * Fix false positive with `belongs_to` -> `belongs_to` for active\_record 4.2
6
+ * Activate active\_record hacks only when Bullet already start
7
+
8
+ ## 4.14.5
9
+
10
+ * Don't execute query when running `to_sql`
11
+ * Send backtrace to `uniform_notifier`
12
+ * Fix sse response check
13
+ * Dynamically delegate available notifiers to UniformNotifier
14
+
3
15
  ## 4.14.4
4
16
 
5
17
  * Fix false N + 1 warnings on Rails 4.2
@@ -10,11 +22,11 @@
10
22
 
11
23
  ## 4.14.2
12
24
 
13
- * Hotfix nil object when add_impossible_object
25
+ * Hotfix nil object when `add_impossible_object`
14
26
 
15
27
  ## 4.14.1
16
28
 
17
- * Fix has_one then has_many associations in rails 4.2
29
+ * Fix `has_one` then `has_many` associations in rails 4.2
18
30
  * Append js and dom to html body in proper position
19
31
 
20
32
  ## 4.14.0 (10/03/2014)
data/Gemfile.mongoid CHANGED
@@ -8,7 +8,5 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', github: 'mongoid/mongoid'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
data/Gemfile.mongoid-2.4 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 2.4.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-2.5 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 2.5.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-2.6 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 2.6.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-2.7 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 2.7.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-2.8 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 2.8.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-3.0 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 3.0.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-3.1 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 3.1.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.mongoid-4.0 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', '~> 4.0.0'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.rails-3.1 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.rails-3.2 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.rails-4.0 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.rails-4.1 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/Gemfile.rails-4.2 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
15
13
 
data/README.md CHANGED
@@ -53,10 +53,13 @@ config.after_initialize do
53
53
  :receiver => 'your_account@jabber.org',
54
54
  :show_online_status => true }
55
55
  Bullet.rails_logger = true
56
+ Bullet.honeybadger = true
56
57
  Bullet.bugsnag = true
57
58
  Bullet.airbrake = true
59
+ Bullet.rollbar = true
58
60
  Bullet.add_footer = true
59
61
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
62
+ Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
60
63
  end
61
64
  ```
62
65
 
@@ -67,14 +70,17 @@ The code above will enable all seven of the Bullet notification systems:
67
70
  * `Bullet.alert`: pop up a JavaScript alert in the browser
68
71
  * `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
69
72
  * `Bullet.rails_logger`: add warnings directly to the Rails log
73
+ * `Bullet.honeybadger`: add notifications to Honeybadger
70
74
  * `Bullet.bugsnag`: add notifications to bugsnag
71
75
  * `Bullet.airbrake`: add notifications to airbrake
76
+ * `Bullet.rollbar`: add notifications to rollbar
72
77
  * `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
73
78
  * `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
74
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.raise`: raise errors, useful for making your specs fail unless they have optimized queries
76
81
  * `Bullet.add_footer`: adds the details in the bottom left corner of the page
77
82
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
83
+ * `Bullet.slack`: add notifications to slack
78
84
 
79
85
  Bullet also allows you to disable any of its detectors.
80
86
 
@@ -154,8 +160,9 @@ The Bullet gem uses rack middleware to profile requests. If you want to use Bull
154
160
  ```ruby
155
161
  Bullet.profile do
156
162
  # do anything
163
+
164
+ warnings = Bullet.warnings
157
165
  end
158
- warnings = Bullet.warnings
159
166
  ```
160
167
 
161
168
  ### 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", ">= 1.6.0"
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")
@@ -8,12 +8,14 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  records = origin_to_a
11
- if records.size > 1
12
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
13
- Bullet::Detector::CounterCache.add_possible_objects(records)
14
- elsif records.size == 1
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
16
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
11
+ if Bullet.start?
12
+ if records.size > 1
13
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
14
+ Bullet::Detector::CounterCache.add_possible_objects(records)
15
+ elsif records.size == 1
16
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
17
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
18
+ end
17
19
  end
18
20
  records
19
21
  end
@@ -24,12 +26,14 @@ module Bullet
24
26
  # include query for one to many associations.
25
27
  # keep this eager loadings.
26
28
  def preload_associations(records, associations, preload_options={})
27
- records = [records].flatten.compact.uniq
28
- return if records.empty?
29
- records.each do |record|
30
- Bullet::Detector::Association.add_object_associations(record, associations)
29
+ if Bullet.start?
30
+ records = [records].flatten.compact.uniq
31
+ return if records.empty?
32
+ records.each do |record|
33
+ Bullet::Detector::Association.add_object_associations(record, associations)
34
+ end
35
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
31
36
  end
32
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
33
37
  origin_preload_associations(records, associations, preload_options={})
34
38
  end
35
39
  end
@@ -39,11 +43,13 @@ module Bullet
39
43
  alias_method :origin_find_with_associations, :find_with_associations
40
44
  def find_with_associations
41
45
  records = origin_find_with_associations
42
- associations = (@eager_load_values + @includes_values).uniq
43
- records.each do |record|
44
- Bullet::Detector::Association.add_object_associations(record, associations)
46
+ if Bullet.start?
47
+ associations = (@eager_load_values + @includes_values).uniq
48
+ records.each do |record|
49
+ Bullet::Detector::Association.add_object_associations(record, associations)
50
+ end
51
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
45
52
  end
46
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
47
53
  records
48
54
  end
49
55
  end
@@ -56,9 +62,11 @@ module Bullet
56
62
  @bullet_eager_loadings = {}
57
63
  records = origin_instantiate(rows)
58
64
 
59
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
60
- objects = eager_loadings_hash.keys
61
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
65
+ if Bullet.start?
66
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
67
+ objects = eager_loadings_hash.keys
68
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
69
+ end
62
70
  end
63
71
  records
64
72
  end
@@ -67,12 +75,14 @@ module Bullet
67
75
  def construct_association(record, join, row)
68
76
  result = origin_construct_association(record, join, row)
69
77
 
70
- associations = join.reflection.name
71
- Bullet::Detector::Association.add_object_associations(record, associations)
72
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
73
- @bullet_eager_loadings[record.class] ||= {}
74
- @bullet_eager_loadings[record.class][record] ||= Set.new
75
- @bullet_eager_loadings[record.class][record] << associations
78
+ if Bullet.start?
79
+ associations = join.reflection.name
80
+ Bullet::Detector::Association.add_object_associations(record, associations)
81
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
82
+ @bullet_eager_loadings[record.class] ||= {}
83
+ @bullet_eager_loadings[record.class][record] ||= Set.new
84
+ @bullet_eager_loadings[record.class][record] << associations
85
+ end
76
86
 
77
87
  result
78
88
  end
@@ -82,31 +92,41 @@ module Bullet
82
92
  # call one to many associations
83
93
  alias_method :origin_load_target, :load_target
84
94
  def load_target
85
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
95
+ if Bullet.start?
96
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
97
+ end
86
98
  origin_load_target
87
99
  end
88
100
 
89
101
  alias_method :origin_first, :first
90
102
  def first(*args)
91
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
103
+ if Bullet.start?
104
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
105
+ end
92
106
  origin_first(*args)
93
107
  end
94
108
 
95
109
  alias_method :origin_last, :last
96
110
  def last(*args)
97
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
111
+ if Bullet.start?
112
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
113
+ end
98
114
  origin_last(*args)
99
115
  end
100
116
 
101
117
  alias_method :origin_empty?, :empty?
102
118
  def empty?
103
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
119
+ if Bullet.start?
120
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
121
+ end
104
122
  origin_empty?
105
123
  end
106
124
 
107
125
  alias_method :origin_include?, :include?
108
126
  def include?(object)
109
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
127
+ if Bullet.start?
128
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
129
+ end
110
130
  origin_include?(object)
111
131
  end
112
132
  end
@@ -117,15 +137,19 @@ module Bullet
117
137
  def load_target
118
138
  # avoid stack level too deep
119
139
  result = origin_load_target
120
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?("load_target") }
121
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
140
+ if Bullet.start?
141
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?("load_target") }
142
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
143
+ end
122
144
  result
123
145
  end
124
146
 
125
147
  alias_method :origin_set_inverse_instance, :set_inverse_instance
126
148
  def set_inverse_instance(record, instance)
127
- if record && we_can_set_the_inverse_on_this?(record)
128
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
149
+ if Bullet.start?
150
+ if record && we_can_set_the_inverse_on_this?(record)
151
+ Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
152
+ end
129
153
  end
130
154
  origin_set_inverse_instance(record, instance)
131
155
  end
@@ -136,7 +160,9 @@ module Bullet
136
160
 
137
161
  def has_cached_counter?
138
162
  result = origin_has_cached_counter?
139
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
163
+ if Bullet.start?
164
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
165
+ end
140
166
  result
141
167
  end
142
168
  end
@@ -145,7 +171,9 @@ module Bullet
145
171
  alias_method :origin_has_cached_counter?, :has_cached_counter?
146
172
  def has_cached_counter?
147
173
  result = origin_has_cached_counter?
148
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
174
+ if Bullet.start?
175
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
176
+ end
149
177
  result
150
178
  end
151
179
  end
@@ -8,12 +8,14 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  records = origin_to_a
11
- if records.size > 1
12
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
13
- Bullet::Detector::CounterCache.add_possible_objects(records)
14
- elsif records.size == 1
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
16
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
11
+ if Bullet.start?
12
+ if records.size > 1
13
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
14
+ Bullet::Detector::CounterCache.add_possible_objects(records)
15
+ elsif records.size == 1
16
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
17
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
18
+ end
17
19
  end
18
20
  records
19
21
  end
@@ -25,12 +27,14 @@ module Bullet
25
27
  alias_method :origin_initialize, :initialize
26
28
  def initialize(records, associations, preload_scope = nil)
27
29
  origin_initialize(records, associations, preload_scope)
28
- records = [records].flatten.compact.uniq
29
- return if records.empty?
30
- records.each do |record|
31
- Bullet::Detector::Association.add_object_associations(record, associations)
30
+ if Bullet.start?
31
+ records = [records].flatten.compact.uniq
32
+ return if records.empty?
33
+ records.each do |record|
34
+ Bullet::Detector::Association.add_object_associations(record, associations)
35
+ end
36
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
32
37
  end
33
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
34
38
  end
35
39
  end
36
40
 
@@ -39,11 +43,13 @@ module Bullet
39
43
  alias_method :origin_find_with_associations, :find_with_associations
40
44
  def find_with_associations
41
45
  records = origin_find_with_associations
42
- associations = (eager_load_values + includes_values).uniq
43
- records.each do |record|
44
- Bullet::Detector::Association.add_object_associations(record, associations)
46
+ if Bullet.start?
47
+ associations = (eager_load_values + includes_values).uniq
48
+ records.each do |record|
49
+ Bullet::Detector::Association.add_object_associations(record, associations)
50
+ end
51
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
45
52
  end
46
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
47
53
  records
48
54
  end
49
55
  end
@@ -56,9 +62,11 @@ module Bullet
56
62
  @bullet_eager_loadings = {}
57
63
  records = origin_instantiate(rows)
58
64
 
59
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
60
- objects = eager_loadings_hash.keys
61
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
65
+ if Bullet.start?
66
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
67
+ objects = eager_loadings_hash.keys
68
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
69
+ end
62
70
  end
63
71
  records
64
72
  end
@@ -67,12 +75,14 @@ module Bullet
67
75
  def construct_association(record, join, row)
68
76
  result = origin_construct_association(record, join, row)
69
77
 
70
- associations = join.reflection.name
71
- Bullet::Detector::Association.add_object_associations(record, associations)
72
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
73
- @bullet_eager_loadings[record.class] ||= {}
74
- @bullet_eager_loadings[record.class][record] ||= Set.new
75
- @bullet_eager_loadings[record.class][record] << associations
78
+ if Bullet.start?
79
+ associations = join.reflection.name
80
+ Bullet::Detector::Association.add_object_associations(record, associations)
81
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
82
+ @bullet_eager_loadings[record.class] ||= {}
83
+ @bullet_eager_loadings[record.class][record] ||= Set.new
84
+ @bullet_eager_loadings[record.class][record] << associations
85
+ end
76
86
 
77
87
  result
78
88
  end
@@ -82,19 +92,25 @@ module Bullet
82
92
  # call one to many associations
83
93
  alias_method :origin_load_target, :load_target
84
94
  def load_target
85
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
95
+ if Bullet.start?
96
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
97
+ end
86
98
  origin_load_target
87
99
  end
88
100
 
89
101
  alias_method :origin_empty?, :empty?
90
102
  def empty?
91
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
103
+ if Bullet.start?
104
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
105
+ end
92
106
  origin_empty?
93
107
  end
94
108
 
95
109
  alias_method :origin_include?, :include?
96
110
  def include?(object)
97
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
111
+ if Bullet.start?
112
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
113
+ end
98
114
  origin_include?(object)
99
115
  end
100
116
  end
@@ -104,8 +120,10 @@ module Bullet
104
120
  alias_method :origin_reader, :reader
105
121
  def reader(force_reload = false)
106
122
  result = origin_reader(force_reload)
107
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
108
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
123
+ if Bullet.start?
124
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
125
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
126
+ end
109
127
  result
110
128
  end
111
129
  end
@@ -113,8 +131,10 @@ module Bullet
113
131
  ::ActiveRecord::Associations::Association.class_eval do
114
132
  alias_method :origin_set_inverse_instance, :set_inverse_instance
115
133
  def set_inverse_instance(record)
116
- if record && invertible_for?(record)
117
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
134
+ if Bullet.start?
135
+ if record && invertible_for?(record)
136
+ Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
137
+ end
118
138
  end
119
139
  origin_set_inverse_instance(record)
120
140
  end
@@ -123,9 +143,11 @@ module Bullet
123
143
  ::ActiveRecord::Associations::HasManyAssociation.class_eval do
124
144
  alias_method :origin_has_cached_counter?, :has_cached_counter?
125
145
 
126
- def has_cached_counter?(reflection = reflection())
146
+ def has_cached_counter?(reflection = reflection)
127
147
  result = origin_has_cached_counter?(reflection)
128
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
148
+ if Bullet.start?
149
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
150
+ end
129
151
  result
130
152
  end
131
153
  end