bullet 5.7.0 → 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.
- checksums.yaml +5 -5
- data/.travis.yml +2 -0
- data/CHANGELOG.md +27 -1
- data/Gemfile.mongoid-7.0 +15 -0
- data/Gemfile.rails-4.0 +1 -1
- data/Gemfile.rails-4.1 +1 -1
- data/Gemfile.rails-4.2 +1 -1
- data/Gemfile.rails-5.0 +1 -1
- data/Gemfile.rails-5.1 +1 -1
- data/Gemfile.rails-5.2 +2 -2
- data/Gemfile.rails-6.0 +15 -0
- data/Guardfile +1 -1
- data/README.md +10 -5
- data/Rakefile +5 -5
- data/bullet.gemspec +12 -6
- data/lib/bullet/active_record4.rb +10 -14
- data/lib/bullet/active_record41.rb +8 -14
- data/lib/bullet/active_record42.rb +16 -22
- data/lib/bullet/active_record5.rb +69 -49
- data/lib/bullet/active_record52.rb +40 -40
- data/lib/bullet/active_record60.rb +245 -0
- data/lib/bullet/bullet_xhr.js +58 -0
- data/lib/bullet/dependency.rb +19 -5
- data/lib/bullet/detector/association.rb +18 -16
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +13 -10
- data/lib/bullet/detector/n_plus_one_query.rb +21 -19
- data/lib/bullet/detector/unused_eager_loading.rb +27 -22
- data/lib/bullet/detector.rb +2 -0
- data/lib/bullet/ext/object.rb +9 -5
- data/lib/bullet/ext/string.rb +3 -1
- data/lib/bullet/mongoid4x.rb +7 -2
- data/lib/bullet/mongoid5x.rb +7 -2
- data/lib/bullet/mongoid6x.rb +11 -6
- data/lib/bullet/mongoid7x.rb +61 -0
- data/lib/bullet/notification/base.rb +21 -15
- data/lib/bullet/notification/counter_cache.rb +2 -0
- data/lib/bullet/notification/n_plus_one_query.rb +6 -4
- data/lib/bullet/notification/unused_eager_loading.rb +6 -4
- data/lib/bullet/notification.rb +2 -0
- data/lib/bullet/notification_collector.rb +2 -1
- data/lib/bullet/rack.rb +52 -31
- data/lib/bullet/registry/association.rb +2 -0
- data/lib/bullet/registry/base.rb +2 -0
- data/lib/bullet/registry/object.rb +2 -0
- data/lib/bullet/registry.rb +2 -0
- data/lib/bullet/stack_trace_filter.rb +57 -21
- data/lib/bullet/version.rb +2 -1
- data/lib/bullet.rb +48 -31
- data/lib/generators/bullet/install_generator.rb +5 -3
- data/perf/benchmark.rb +9 -7
- data/rails/init.rb +2 -0
- data/spec/bullet/detector/association_spec.rb +2 -0
- data/spec/bullet/detector/base_spec.rb +2 -0
- data/spec/bullet/detector/counter_cache_spec.rb +2 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +33 -8
- data/spec/bullet/detector/unused_eager_loading_spec.rb +2 -0
- data/spec/bullet/ext/object_spec.rb +12 -5
- data/spec/bullet/ext/string_spec.rb +2 -0
- data/spec/bullet/notification/base_spec.rb +8 -6
- data/spec/bullet/notification/counter_cache_spec.rb +3 -1
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -1
- data/spec/bullet/notification/unused_eager_loading_spec.rb +3 -1
- data/spec/bullet/notification_collector_spec.rb +2 -0
- data/spec/bullet/rack_spec.rb +22 -12
- data/spec/bullet/registry/association_spec.rb +4 -2
- data/spec/bullet/registry/base_spec.rb +5 -3
- data/spec/bullet/registry/object_spec.rb +2 -0
- data/spec/bullet_spec.rb +9 -7
- data/spec/integration/active_record/association_spec.rb +70 -19
- data/spec/integration/counter_cache_spec.rb +5 -3
- data/spec/integration/mongoid/association_spec.rb +2 -0
- data/spec/models/address.rb +2 -0
- data/spec/models/author.rb +2 -0
- data/spec/models/base_user.rb +2 -0
- data/spec/models/category.rb +2 -0
- data/spec/models/city.rb +2 -0
- data/spec/models/client.rb +4 -0
- data/spec/models/comment.rb +2 -0
- data/spec/models/company.rb +2 -0
- data/spec/models/country.rb +2 -0
- data/spec/models/document.rb +2 -0
- data/spec/models/entry.rb +2 -0
- data/spec/models/firm.rb +3 -0
- data/spec/models/folder.rb +2 -0
- data/spec/models/group.rb +4 -0
- data/spec/models/mongoid/address.rb +3 -1
- data/spec/models/mongoid/category.rb +4 -2
- data/spec/models/mongoid/comment.rb +3 -1
- data/spec/models/mongoid/company.rb +3 -1
- data/spec/models/mongoid/entry.rb +3 -1
- data/spec/models/mongoid/post.rb +6 -4
- data/spec/models/mongoid/user.rb +2 -0
- data/spec/models/newspaper.rb +2 -0
- data/spec/models/page.rb +2 -0
- data/spec/models/person.rb +2 -0
- data/spec/models/pet.rb +2 -0
- data/spec/models/post.rb +17 -0
- data/spec/models/relationship.rb +2 -0
- data/spec/models/reply.rb +2 -0
- data/spec/models/student.rb +2 -0
- data/spec/models/submission.rb +2 -0
- data/spec/models/teacher.rb +2 -0
- data/spec/models/user.rb +2 -0
- data/spec/models/writer.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/bullet_ext.rb +2 -0
- data/spec/support/mongo_seed.rb +32 -30
- data/spec/support/rack_double.rb +9 -16
- data/spec/support/sqlite_seed.rb +84 -75
- data/tasks/bullet_tasks.rake +2 -0
- data/test.sh +2 -0
- data/update.sh +1 -0
- metadata +17 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 749d1d92dc0373b1f2521c85825dfea656e985c438cdfafe774242b31f25c2d5
|
|
4
|
+
data.tar.gz: 4e76a9da65613f2b9cf3802f4969f84c1e5bb9849c5892898fa9d999fde3900c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72f8f18edecb79d8631a215229afb71bb94050c0fcc65794a88dc3adf21545acf4ae38eb59bd6bdfa0e34609854ab149d02f47e761fba00452e28f2575306376
|
|
7
|
+
data.tar.gz: 94058fcb502d63ce470b6dfa06d05dd367c8a7e251948040b91c22164d6583d8a82ab120bb2a42d109c121170042573c9964aaa55ebc0093c07adc1fb8f23fd5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
## Next Release
|
|
2
|
+
|
|
3
|
+
## 6.0.0 (02/22/2019)
|
|
4
|
+
|
|
5
|
+
* Add XHR support to Bullet
|
|
6
|
+
* Support Rails 6.0
|
|
7
|
+
* Handle case where ID is manually set on unpersisted record
|
|
8
|
+
|
|
9
|
+
## 5.9.0 (11/11/2018)
|
|
10
|
+
|
|
11
|
+
* Require Ruby 2.3+
|
|
12
|
+
* Support Mongo 7.x
|
|
13
|
+
|
|
14
|
+
## 5.8.0 (10/29/2018)
|
|
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
|
|
24
|
+
* Exclude configured bundler path in addition to '/vendor'
|
|
25
|
+
* Fix `caller_path` in `excluded_stacktrace_path`
|
|
26
|
+
* Update `uniform_notifier` dependency to add Sentry support
|
|
27
|
+
* Integrate awesomecode.io and refactor code
|
|
2
28
|
|
|
3
29
|
## 5.7.0 (12/03/2017)
|
|
4
30
|
|
data/Gemfile.mongoid-7.0
ADDED
|
@@ -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
data/Gemfile.rails-4.2
CHANGED
data/Gemfile.rails-5.0
CHANGED
data/Gemfile.rails-5.1
CHANGED
data/Gemfile.rails-5.2
CHANGED
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/Guardfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# A sample Guardfile
|
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
|
3
3
|
|
|
4
|
-
guard 'rspec', :
|
|
4
|
+
guard 'rspec', version: 2, all_after_pass: false, all_on_start: false, cli: '--color --format nested --fail-fast' do
|
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
7
7
|
watch('spec/spec_helper.rb') { 'spec' }
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/bullet)
|
|
4
4
|
[](http://travis-ci.org/flyerhzm/bullet)
|
|
5
|
-
|
|
5
|
+
[](https://awesomecode.io/repos/flyerhzm/bullet)
|
|
6
6
|
[](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.
|
|
@@ -48,6 +48,7 @@ Bullet won't do ANYTHING unless you tell it to explicitly. Append to
|
|
|
48
48
|
```ruby
|
|
49
49
|
config.after_initialize do
|
|
50
50
|
Bullet.enable = true
|
|
51
|
+
Bullet.sentry = true
|
|
51
52
|
Bullet.alert = true
|
|
52
53
|
Bullet.bullet_logger = true
|
|
53
54
|
Bullet.console = true
|
|
@@ -63,7 +64,7 @@ config.after_initialize do
|
|
|
63
64
|
Bullet.rollbar = true
|
|
64
65
|
Bullet.add_footer = true
|
|
65
66
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
|
66
|
-
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] ]
|
|
67
68
|
Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
|
|
68
69
|
end
|
|
69
70
|
```
|
|
@@ -82,9 +83,12 @@ The code above will enable all of the Bullet notification systems:
|
|
|
82
83
|
* `Bullet.bugsnag`: add notifications to bugsnag
|
|
83
84
|
* `Bullet.airbrake`: add notifications to airbrake
|
|
84
85
|
* `Bullet.rollbar`: add notifications to rollbar
|
|
86
|
+
* `Bullet.sentry`: add notifications to sentry
|
|
85
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.
|
|
86
88
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
|
87
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.
|
|
88
92
|
* `Bullet.slack`: add notifications to slack
|
|
89
93
|
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
|
90
94
|
|
|
@@ -124,10 +128,11 @@ class ApplicationController < ActionController::Base
|
|
|
124
128
|
around_action :skip_bullet
|
|
125
129
|
|
|
126
130
|
def skip_bullet
|
|
131
|
+
previous_value = Bullet.enable?
|
|
127
132
|
Bullet.enable = false
|
|
128
133
|
yield
|
|
129
134
|
ensure
|
|
130
|
-
Bullet.enable =
|
|
135
|
+
Bullet.enable = previous_value
|
|
131
136
|
end
|
|
132
137
|
end
|
|
133
138
|
```
|
|
@@ -178,7 +183,7 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
|
|
|
178
183
|
|
|
179
184
|
### Profile a job
|
|
180
185
|
|
|
181
|
-
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
|
|
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
|
|
182
187
|
|
|
183
188
|
```ruby
|
|
184
189
|
Bullet.profile do
|
|
@@ -216,7 +221,7 @@ end
|
|
|
216
221
|
Then wrap each test in Bullet api.
|
|
217
222
|
|
|
218
223
|
```ruby
|
|
219
|
-
# spec/
|
|
224
|
+
# spec/rails_helper.rb
|
|
220
225
|
if Bullet.enable?
|
|
221
226
|
config.before(:each) do
|
|
222
227
|
Bullet.start_request
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
|
2
2
|
require 'bundler'
|
|
3
3
|
Bundler.setup
|
|
4
4
|
|
|
@@ -12,11 +12,11 @@ task :build do
|
|
|
12
12
|
system 'gem build bullet.gemspec'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
task :
|
|
15
|
+
task install: :build do
|
|
16
16
|
system "sudo gem install bullet-#{Bullet::VERSION}.gem"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
task :
|
|
19
|
+
task release: :build do
|
|
20
20
|
puts "Tagging #{Bullet::VERSION}..."
|
|
21
21
|
system "git tag -a #{Bullet::VERSION} -m 'Tagging #{Bullet::VERSION}'"
|
|
22
22
|
puts 'Pushing to Github...'
|
|
@@ -30,7 +30,7 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
RSpec::Core::RakeTask.new('spec:progress') do |spec|
|
|
33
|
-
spec.rspec_opts = %w
|
|
33
|
+
spec.rspec_opts = %w[--format progress]
|
|
34
34
|
spec.pattern = 'spec/**/*_spec.rb'
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -48,4 +48,4 @@ rescue LoadError
|
|
|
48
48
|
puts 'RDocTask is not supported for this platform'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
task :
|
|
51
|
+
task default: :spec
|
data/bullet.gemspec
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
|
3
5
|
|
|
4
6
|
require 'bullet/version'
|
|
5
7
|
|
|
@@ -9,19 +11,23 @@ Gem::Specification.new do |s|
|
|
|
9
11
|
s.platform = Gem::Platform::RUBY
|
|
10
12
|
s.authors = ['Richard Huang']
|
|
11
13
|
s.email = ['flyerhzm@gmail.com']
|
|
12
|
-
s.homepage = '
|
|
14
|
+
s.homepage = 'https://github.com/flyerhzm/bullet'
|
|
13
15
|
s.summary = 'help to kill N+1 queries and unused eager loading.'
|
|
14
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
|
+
}
|
|
15
21
|
|
|
16
|
-
s.license
|
|
22
|
+
s.license = 'MIT'
|
|
17
23
|
|
|
24
|
+
s.required_ruby_version = '>= 2.3'
|
|
18
25
|
s.required_rubygems_version = '>= 1.3.6'
|
|
19
26
|
|
|
20
27
|
s.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
|
21
|
-
s.add_runtime_dependency 'uniform_notifier', '~> 1.
|
|
28
|
+
s.add_runtime_dependency 'uniform_notifier', '~> 1.11'
|
|
22
29
|
|
|
23
30
|
s.files = `git ls-files`.split("\n")
|
|
24
31
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
25
32
|
s.require_paths = ['lib']
|
|
26
33
|
end
|
|
27
|
-
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module ActiveRecord
|
|
3
5
|
def self.enable
|
|
@@ -46,21 +48,12 @@ module Bullet
|
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
::ActiveRecord::Persistence.class_eval do
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
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)
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
|
-
alias_method_chain :
|
|
56
|
-
|
|
57
|
-
def save_with_bullet!(*args, &proc)
|
|
58
|
-
was_new_record = new_record?
|
|
59
|
-
save_without_bullet!(*args, &proc).tap do |result|
|
|
60
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
alias_method_chain :save!, :bullet
|
|
56
|
+
alias_method_chain :_create_record, :bullet
|
|
64
57
|
end
|
|
65
58
|
|
|
66
59
|
::ActiveRecord::Associations::Preloader.class_eval do
|
|
@@ -72,6 +65,7 @@ module Bullet
|
|
|
72
65
|
if Bullet.start?
|
|
73
66
|
records = [records].flatten.compact.uniq
|
|
74
67
|
return if records.empty?
|
|
68
|
+
|
|
75
69
|
records.each do |record|
|
|
76
70
|
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
77
71
|
end
|
|
@@ -105,7 +99,7 @@ module Bullet
|
|
|
105
99
|
records = origin_instantiate(rows)
|
|
106
100
|
|
|
107
101
|
if Bullet.start?
|
|
108
|
-
@bullet_eager_loadings.each do |
|
|
102
|
+
@bullet_eager_loadings.each do |_klazz, eager_loadings_hash|
|
|
109
103
|
objects = eager_loadings_hash.keys
|
|
110
104
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
|
111
105
|
end
|
|
@@ -187,6 +181,7 @@ module Bullet
|
|
|
187
181
|
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
188
182
|
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
|
189
183
|
|
|
184
|
+
# rubocop:disable Style/MethodCallWithoutArgsParentheses
|
|
190
185
|
def has_cached_counter?(reflection = reflection())
|
|
191
186
|
result = origin_has_cached_counter?(reflection)
|
|
192
187
|
if Bullet.start? && !result
|
|
@@ -194,6 +189,7 @@ module Bullet
|
|
|
194
189
|
end
|
|
195
190
|
result
|
|
196
191
|
end
|
|
192
|
+
# rubocop:enable Style/MethodCallWithoutArgsParentheses
|
|
197
193
|
end
|
|
198
194
|
end
|
|
199
195
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module ActiveRecord
|
|
3
5
|
def self.enable
|
|
@@ -48,21 +50,12 @@ module Bullet
|
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
::ActiveRecord::Persistence.class_eval do
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
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)
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
|
-
alias_method_chain :
|
|
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
|
|
58
|
+
alias_method_chain :_create_record, :bullet
|
|
66
59
|
end
|
|
67
60
|
|
|
68
61
|
::ActiveRecord::Associations::Preloader.class_eval do
|
|
@@ -87,6 +80,7 @@ module Bullet
|
|
|
87
80
|
alias_method :origin_find_with_associations, :find_with_associations
|
|
88
81
|
def find_with_associations
|
|
89
82
|
return origin_find_with_associations { |r| yield r } if block_given?
|
|
83
|
+
|
|
90
84
|
records = origin_find_with_associations
|
|
91
85
|
if Bullet.start?
|
|
92
86
|
associations = (eager_load_values + includes_values).uniq
|
|
@@ -108,7 +102,7 @@ module Bullet
|
|
|
108
102
|
records = origin_instantiate(result_set, aliases)
|
|
109
103
|
|
|
110
104
|
if Bullet.start?
|
|
111
|
-
@bullet_eager_loadings.each do |
|
|
105
|
+
@bullet_eager_loadings.each do |_klazz, eager_loadings_hash|
|
|
112
106
|
objects = eager_loadings_hash.keys
|
|
113
107
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
|
114
108
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module ActiveRecord
|
|
3
5
|
def self.enable
|
|
@@ -42,21 +44,12 @@ module Bullet
|
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
::ActiveRecord::Persistence.class_eval do
|
|
45
|
-
def
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
alias_method_chain :save, :bullet
|
|
52
|
-
|
|
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
|
|
47
|
+
def _create_record_with_bullet(*args)
|
|
48
|
+
_create_record_without_bullet(*args).tap do
|
|
49
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
|
|
57
50
|
end
|
|
58
51
|
end
|
|
59
|
-
alias_method_chain :
|
|
52
|
+
alias_method_chain :_create_record, :bullet
|
|
60
53
|
end
|
|
61
54
|
|
|
62
55
|
::ActiveRecord::Relation.class_eval do
|
|
@@ -102,6 +95,7 @@ module Bullet
|
|
|
102
95
|
alias_method :origin_find_with_associations, :find_with_associations
|
|
103
96
|
def find_with_associations
|
|
104
97
|
return origin_find_with_associations { |r| yield r } if block_given?
|
|
98
|
+
|
|
105
99
|
records = origin_find_with_associations
|
|
106
100
|
if Bullet.start?
|
|
107
101
|
associations = (eager_load_values + includes_values).uniq
|
|
@@ -124,7 +118,7 @@ module Bullet
|
|
|
124
118
|
records = origin_instantiate(result_set, aliases)
|
|
125
119
|
|
|
126
120
|
if Bullet.start?
|
|
127
|
-
@bullet_eager_loadings.each do |
|
|
121
|
+
@bullet_eager_loadings.each do |_klazz, eager_loadings_hash|
|
|
128
122
|
objects = eager_loadings_hash.keys
|
|
129
123
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
|
130
124
|
end
|
|
@@ -138,14 +132,14 @@ module Bullet
|
|
|
138
132
|
parent.children.each do |node|
|
|
139
133
|
key = aliases.column_alias(node, node.primary_key)
|
|
140
134
|
id = row[key]
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
135
|
+
next unless id.nil?
|
|
136
|
+
|
|
137
|
+
associations = node.reflection.name
|
|
138
|
+
Bullet::Detector::Association.add_object_associations(ar_parent, associations)
|
|
139
|
+
Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
|
|
140
|
+
@bullet_eager_loadings[ar_parent.class] ||= {}
|
|
141
|
+
@bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
|
|
142
|
+
@bullet_eager_loadings[ar_parent.class][ar_parent] << associations
|
|
149
143
|
end
|
|
150
144
|
end
|
|
151
145
|
end
|