bullet 5.7.5 → 6.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.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +17 -14
  4. data/Gemfile.mongoid-7.0 +15 -0
  5. data/Gemfile.rails-4.0 +1 -1
  6. data/Gemfile.rails-4.1 +1 -1
  7. data/Gemfile.rails-4.2 +1 -1
  8. data/Gemfile.rails-5.0 +1 -1
  9. data/Gemfile.rails-5.1 +1 -1
  10. data/Gemfile.rails-5.2 +2 -2
  11. data/Gemfile.rails-6.0 +15 -0
  12. data/README.md +8 -5
  13. data/Rakefile +1 -1
  14. data/bullet.gemspec +8 -3
  15. data/lib/bullet/active_record4.rb +5 -13
  16. data/lib/bullet/active_record41.rb +5 -13
  17. data/lib/bullet/active_record42.rb +6 -13
  18. data/lib/bullet/active_record5.rb +15 -13
  19. data/lib/bullet/active_record52.rb +12 -13
  20. data/lib/bullet/active_record60.rb +245 -0
  21. data/lib/bullet/bullet_xhr.js +58 -0
  22. data/lib/bullet/dependency.rb +17 -5
  23. data/lib/bullet/detector/association.rb +4 -4
  24. data/lib/bullet/detector/counter_cache.rb +4 -3
  25. data/lib/bullet/detector/n_plus_one_query.rb +13 -13
  26. data/lib/bullet/detector/unused_eager_loading.rb +2 -1
  27. data/lib/bullet/ext/object.rb +5 -3
  28. data/lib/bullet/ext/string.rb +1 -1
  29. data/lib/bullet/mongoid4x.rb +1 -0
  30. data/lib/bullet/mongoid5x.rb +1 -0
  31. data/lib/bullet/mongoid6x.rb +5 -4
  32. data/lib/bullet/mongoid7x.rb +61 -0
  33. data/lib/bullet/notification/base.rb +1 -1
  34. data/lib/bullet/rack.rb +45 -27
  35. data/lib/bullet/stack_trace_filter.rb +43 -25
  36. data/lib/bullet/version.rb +1 -1
  37. data/lib/bullet.rb +21 -5
  38. data/lib/generators/bullet/install_generator.rb +3 -3
  39. data/spec/bullet/detector/n_plus_one_query_spec.rb +23 -0
  40. data/spec/bullet/ext/object_spec.rb +9 -4
  41. data/spec/bullet/rack_spec.rb +12 -3
  42. data/spec/integration/active_record/association_spec.rb +52 -3
  43. data/spec/integration/counter_cache_spec.rb +1 -1
  44. data/spec/models/client.rb +2 -0
  45. data/spec/models/firm.rb +1 -0
  46. data/spec/models/group.rb +4 -0
  47. data/spec/models/post.rb +15 -0
  48. data/spec/support/sqlite_seed.rb +9 -2
  49. data/test.sh +2 -0
  50. data/update.sh +1 -0
  51. metadata +16 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb27c10f2796dc6cc38899be2b88943f6c124d80
4
- data.tar.gz: c89d95e08212b3bf8da49f2ce4c542ec2aa3021d
2
+ SHA256:
3
+ metadata.gz: 749d1d92dc0373b1f2521c85825dfea656e985c438cdfafe774242b31f25c2d5
4
+ data.tar.gz: 4e76a9da65613f2b9cf3802f4969f84c1e5bb9849c5892898fa9d999fde3900c
5
5
  SHA512:
6
- metadata.gz: 8f4d67bebf52a6730fa623bb150717e56c052605fc339f37d89d915af0981e442200e2bfee5c3405e6269d0907dc4e4f89fd2965000e637555aa8614580837c0
7
- data.tar.gz: 3fbfc65e37e50444107e153050b33f66fe51037fd9d325438015d51c71f4a5ccb387e9b76ba28a2c753c9f9227653686535c857f457c80d62213cdda070b9c18
6
+ metadata.gz: 72f8f18edecb79d8631a215229afb71bb94050c0fcc65794a88dc3adf21545acf4ae38eb59bd6bdfa0e34609854ab149d02f47e761fba00452e28f2575306376
7
+ data.tar.gz: 94058fcb502d63ce470b6dfa06d05dd367c8a7e251948040b91c22164d6583d8a82ab120bb2a42d109c121170042573c9964aaa55ebc0093c07adc1fb8f23fd5
data/.travis.yml CHANGED
@@ -3,6 +3,8 @@ language: ruby
3
3
  rvm:
4
4
  - 2.3.0
5
5
  gemfile:
6
+ - Gemfile.rails-6.0
7
+ - Gemfile.rails-5.2
6
8
  - Gemfile.rails-5.1
7
9
  - Gemfile.rails-5.0
8
10
  - Gemfile.rails-4.2
data/CHANGELOG.md CHANGED
@@ -1,27 +1,30 @@
1
1
  ## Next Release
2
2
 
3
- ## 5.7.5 (12/03/2018)
3
+ ## 6.0.0 (02/22/2019)
4
4
 
5
- * Fix duplicate logs in mongoid 4.x and 5.x version
6
- * Add magic comment frozen_string_literal: true
5
+ * Add XHR support to Bullet
6
+ * Support Rails 6.0
7
+ * Handle case where ID is manually set on unpersisted record
7
8
 
8
- ## 5.7.4 (10/03/2018)
9
+ ## 5.9.0 (11/11/2018)
9
10
 
10
- * Avoid Bullet from making extra queries in mongoid6
11
- * Use caller for ruby 1.9 while caller_locations for 2.0+
11
+ * Require Ruby 2.3+
12
+ * Support Mongo 7.x
12
13
 
13
- ## 5.7.3 (17/02/2018)
14
+ ## 5.8.0 (10/29/2018)
14
15
 
16
+ * Fix through reflection for rails 5.x
17
+ * Fix false positive in after_save/after_create callbacks
18
+ * Don't triger a preload error on "manual" preloads
19
+ * Avoid Bullet from making extra queries in mongoid6
20
+ * Support option for #first and #last on mongoid6.x
21
+ * Fix duplicate logs in mongoid 4.x and 5.x version
22
+ * Use caller for ruby 1.9 while caller_locations for 2.0+
23
+ * Extend stacktrace matching for sub-file precision
15
24
  * Exclude configured bundler path in addition to '/vendor'
16
- * Support rails 5.1.5
17
-
18
- ## 5.7.2 (18/01/2018)
19
-
20
25
  * Fix `caller_path` in `excluded_stacktrace_path`
21
-
22
- ## 5.7.1 (07/01/2017)
23
-
24
26
  * Update `uniform_notifier` dependency to add Sentry support
27
+ * Integrate awesomecode.io and refactor code
25
28
 
26
29
  ## 5.7.0 (12/03/2017)
27
30
 
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.0'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mongoid', '~> 7.0.0'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/Gemfile.rails-4.0 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.0.0'
6
- gem 'sqlite3', platforms: [:ruby]
6
+ gem 'sqlite3', '~> 1.3.6', platforms: [:ruby]
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
data/Gemfile.rails-4.1 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
data/Gemfile.rails-4.2 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.2.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
data/Gemfile.rails-5.0 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.0.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
data/Gemfile.rails-5.1 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.1.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
data/Gemfile.rails-5.2 CHANGED
@@ -2,8 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 5.2.0.beta2'
6
- gem 'sqlite3'
5
+ gem 'rails', '~> 5.2.0'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
data/Gemfile.rails-6.0 ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '6.0.0.rc1'
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/bullet.png)](http://badge.fury.io/rb/bullet)
4
4
  [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.png)](http://travis-ci.org/flyerhzm/bullet)
5
- [![AwesomeCode Status](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/projects/2)
5
+ [![AwesomeCode Status for flyerhzm/bullet](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/repos/flyerhzm/bullet)
6
6
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
7
7
 
8
8
  The Bullet gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
@@ -64,7 +64,7 @@ config.after_initialize do
64
64
  Bullet.rollbar = true
65
65
  Bullet.add_footer = true
66
66
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
67
- Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
67
+ Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
68
68
  Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
69
69
  end
70
70
  ```
@@ -87,6 +87,8 @@ The code above will enable all of the Bullet notification systems:
87
87
  * `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.
88
88
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
89
89
  * `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
90
+ 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
91
+ item is a line number, a Range of line numbers, or a (bare) method name, to exclude only particular lines in a file.
90
92
  * `Bullet.slack`: add notifications to slack
91
93
  * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
92
94
 
@@ -126,10 +128,11 @@ class ApplicationController < ActionController::Base
126
128
  around_action :skip_bullet
127
129
 
128
130
  def skip_bullet
131
+ previous_value = Bullet.enable?
129
132
  Bullet.enable = false
130
133
  yield
131
134
  ensure
132
- Bullet.enable = true
135
+ Bullet.enable = previous_value
133
136
  end
134
137
  end
135
138
  ```
@@ -180,7 +183,7 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
180
183
 
181
184
  ### Profile a job
182
185
 
183
- The Bullet gem uses rack middleware to profile requests. If you want to use Bullet without an http server, like to profile a job, you can use use profile method and fetch warnings
186
+ The Bullet gem uses rack middleware to profile requests. If you want to use Bullet without an http server, like to profile a job, you can use the profile method and fetch warnings
184
187
 
185
188
  ```ruby
186
189
  Bullet.profile do
@@ -218,7 +221,7 @@ end
218
221
  Then wrap each test in Bullet api.
219
222
 
220
223
  ```ruby
221
- # spec/spec_helper.rb
224
+ # spec/rails_helper.rb
222
225
  if Bullet.enable?
223
226
  config.before(:each) do
224
227
  Bullet.start_request
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
2
2
  require 'bundler'
3
3
  Bundler.setup
4
4
 
data/bullet.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib/', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require 'bullet/version'
@@ -14,13 +14,18 @@ Gem::Specification.new do |s|
14
14
  s.homepage = 'https://github.com/flyerhzm/bullet'
15
15
  s.summary = 'help to kill N+1 queries and unused eager loading.'
16
16
  s.description = 'help to kill N+1 queries and unused eager loading.'
17
+ s.metadata = {
18
+ 'changelog_uri' => 'https://github.com/flyerhzm/bullet/blob/master/CHANGELOG.md',
19
+ 'source_code_uri' => 'https://github.com/flyerhzm/bullet'
20
+ }
17
21
 
18
- s.license = 'MIT'
22
+ s.license = 'MIT'
19
23
 
24
+ s.required_ruby_version = '>= 2.3'
20
25
  s.required_rubygems_version = '>= 1.3.6'
21
26
 
22
27
  s.add_runtime_dependency 'activesupport', '>= 3.0.0'
23
- s.add_runtime_dependency 'uniform_notifier', '~> 1.11.0'
28
+ s.add_runtime_dependency 'uniform_notifier', '~> 1.11'
24
29
 
25
30
  s.files = `git ls-files`.split("\n")
26
31
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -48,21 +48,12 @@ module Bullet
48
48
  end
49
49
 
50
50
  ::ActiveRecord::Persistence.class_eval do
51
- def save_with_bullet(*args, &proc)
52
- was_new_record = new_record?
53
- save_without_bullet(*args, &proc).tap do |result|
54
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
51
+ def _create_record_with_bullet(*args)
52
+ _create_record_without_bullet(*args).tap do
53
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
55
54
  end
56
55
  end
57
- alias_method_chain :save, :bullet
58
-
59
- def save_with_bullet!(*args, &proc)
60
- was_new_record = new_record?
61
- save_without_bullet!(*args, &proc).tap do |result|
62
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
63
- end
64
- end
65
- alias_method_chain :save!, :bullet
56
+ alias_method_chain :_create_record, :bullet
66
57
  end
67
58
 
68
59
  ::ActiveRecord::Associations::Preloader.class_eval do
@@ -74,6 +65,7 @@ module Bullet
74
65
  if Bullet.start?
75
66
  records = [records].flatten.compact.uniq
76
67
  return if records.empty?
68
+
77
69
  records.each do |record|
78
70
  Bullet::Detector::Association.add_object_associations(record, associations)
79
71
  end
@@ -50,21 +50,12 @@ module Bullet
50
50
  end
51
51
 
52
52
  ::ActiveRecord::Persistence.class_eval do
53
- def save_with_bullet(*args, &proc)
54
- was_new_record = new_record?
55
- save_without_bullet(*args, &proc).tap do |result|
56
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
53
+ def _create_record_with_bullet(*args)
54
+ _create_record_without_bullet(*args).tap do
55
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
57
56
  end
58
57
  end
59
- alias_method_chain :save, :bullet
60
-
61
- def save_with_bullet!(*args, &proc)
62
- was_new_record = new_record?
63
- save_without_bullet!(*args, &proc).tap do |result|
64
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
65
- end
66
- end
67
- alias_method_chain :save!, :bullet
58
+ alias_method_chain :_create_record, :bullet
68
59
  end
69
60
 
70
61
  ::ActiveRecord::Associations::Preloader.class_eval do
@@ -89,6 +80,7 @@ module Bullet
89
80
  alias_method :origin_find_with_associations, :find_with_associations
90
81
  def find_with_associations
91
82
  return origin_find_with_associations { |r| yield r } if block_given?
83
+
92
84
  records = origin_find_with_associations
93
85
  if Bullet.start?
94
86
  associations = (eager_load_values + includes_values).uniq
@@ -44,21 +44,12 @@ module Bullet
44
44
  end
45
45
 
46
46
  ::ActiveRecord::Persistence.class_eval do
47
- def save_with_bullet(*args, &proc)
48
- was_new_record = new_record?
49
- save_without_bullet(*args, &proc).tap do |result|
50
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
47
+ def _create_record_with_bullet(*args)
48
+ _create_record_without_bullet(*args).tap do
49
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
51
50
  end
52
51
  end
53
- alias_method_chain :save, :bullet
54
-
55
- def save_with_bullet!(*args, &proc)
56
- was_new_record = new_record?
57
- save_without_bullet!(*args, &proc).tap do |result|
58
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
59
- end
60
- end
61
- alias_method_chain :save!, :bullet
52
+ alias_method_chain :_create_record, :bullet
62
53
  end
63
54
 
64
55
  ::ActiveRecord::Relation.class_eval do
@@ -104,6 +95,7 @@ module Bullet
104
95
  alias_method :origin_find_with_associations, :find_with_associations
105
96
  def find_with_associations
106
97
  return origin_find_with_associations { |r| yield r } if block_given?
98
+
107
99
  records = origin_find_with_associations
108
100
  if Bullet.start?
109
101
  associations = (eager_load_values + includes_values).uniq
@@ -141,6 +133,7 @@ module Bullet
141
133
  key = aliases.column_alias(node, node.primary_key)
142
134
  id = row[key]
143
135
  next unless id.nil?
136
+
144
137
  associations = node.reflection.name
145
138
  Bullet::Detector::Association.add_object_associations(ar_parent, associations)
146
139
  Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@@ -2,17 +2,10 @@
2
2
 
3
3
  module Bullet
4
4
  module SaveWithBulletSupport
5
- def save(*args)
6
- was_new_record = new_record?
7
- super(*args).tap do |result|
8
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
9
- end
10
- end
11
-
12
- def save!(*args)
13
- was_new_record = new_record?
14
- super(*args).tap do |result|
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
5
+ def _create_record(*)
6
+ super do
7
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
+ yield(self) if block_given?
16
9
  end
17
10
  end
18
11
  end
@@ -82,6 +75,7 @@ module Bullet
82
75
  # add includes in scope
83
76
  def find_with_associations
84
77
  return super { |r| yield r } if block_given?
78
+
85
79
  records = super
86
80
  if Bullet.start?
87
81
  associations = (eager_load_values + includes_values).uniq
@@ -132,6 +126,7 @@ module Bullet
132
126
  key = aliases.column_alias(node, node.primary_key)
133
127
  id = row[key]
134
128
  next unless id.nil?
129
+
135
130
  associations = node.reflection.name
136
131
  Bullet::Detector::Association.add_object_associations(ar_parent, associations)
137
132
  Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@@ -168,11 +163,18 @@ module Bullet
168
163
 
169
164
  if Bullet.start?
170
165
  if is_a? ::ActiveRecord::Associations::ThroughAssociation
171
- Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
172
- association = owner.association through_reflection.name
166
+ refl = reflection.through_reflection
167
+ Bullet::Detector::NPlusOneQuery.call_association(owner, refl.name)
168
+ association = owner.association refl.name
173
169
  Array(association.target).each do |through_record|
174
170
  Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
175
171
  end
172
+
173
+ if refl.through_reflection?
174
+ refl = refl.through_reflection while refl.through_reflection?
175
+
176
+ Bullet::Detector::NPlusOneQuery.call_association(owner, refl.name)
177
+ end
176
178
  end
177
179
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
178
180
  if records.first.class.name !~ /^HABTM_/
@@ -2,17 +2,10 @@
2
2
 
3
3
  module Bullet
4
4
  module SaveWithBulletSupport
5
- def save(*args)
6
- was_new_record = new_record?
7
- super(*args).tap do |result|
8
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
9
- end
10
- end
11
-
12
- def save!(*args)
13
- was_new_record = new_record?
14
- super(*args).tap do |result|
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
5
+ def _create_record(*)
6
+ super do
7
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
8
+ yield(self) if block_given?
16
9
  end
17
10
  end
18
11
  end
@@ -82,6 +75,7 @@ module Bullet
82
75
  # add includes in scope
83
76
  def find_with_associations
84
77
  return super { |r| yield r } if block_given?
78
+
85
79
  records = super
86
80
  if Bullet.start?
87
81
  associations = (eager_load_values + includes_values).uniq
@@ -115,6 +109,7 @@ module Bullet
115
109
  key = aliases.column_alias(node, node.primary_key)
116
110
  id = row[key]
117
111
  next unless id.nil?
112
+
118
113
  associations = node.reflection.name
119
114
  Bullet::Detector::Association.add_object_associations(ar_parent, associations)
120
115
  Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@@ -151,11 +146,15 @@ module Bullet
151
146
 
152
147
  if Bullet.start?
153
148
  if is_a? ::ActiveRecord::Associations::ThroughAssociation
154
- Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
155
- association = owner.association through_reflection.name
149
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
150
+ association = owner.association reflection.through_reflection.name
156
151
  Array(association.target).each do |through_record|
157
152
  Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
158
153
  end
154
+
155
+ if reflection.through_reflection != through_reflection
156
+ Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
157
+ end
159
158
  end
160
159
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
161
160
  if records.first.class.name !~ /^HABTM_/