bullet 5.5.0 → 6.1.5
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/.github/workflows/main.yml +66 -0
- data/CHANGELOG.md +83 -1
- data/Gemfile +6 -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 +2 -2
- data/Gemfile.rails-5.1 +15 -0
- data/Gemfile.rails-5.2 +15 -0
- data/Gemfile.rails-6.0 +15 -0
- data/Gemfile.rails-6.1 +15 -0
- data/Guardfile +2 -2
- data/Hacking.md +1 -1
- data/README.md +58 -37
- data/Rakefile +20 -21
- data/bullet.gemspec +21 -15
- data/lib/bullet/active_job.rb +13 -0
- data/lib/bullet/active_record4.rb +15 -34
- data/lib/bullet/active_record41.rb +14 -31
- data/lib/bullet/active_record42.rb +23 -36
- data/lib/bullet/active_record5.rb +178 -158
- data/lib/bullet/active_record52.rb +251 -0
- data/lib/bullet/active_record60.rb +278 -0
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +64 -0
- data/lib/bullet/dependency.rb +60 -32
- data/lib/bullet/detector/association.rb +41 -32
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +25 -17
- data/lib/bullet/detector/n_plus_one_query.rb +38 -24
- data/lib/bullet/detector/unused_eager_loading.rb +35 -26
- 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 +9 -8
- data/lib/bullet/mongoid5x.rb +9 -8
- data/lib/bullet/mongoid6x.rb +13 -12
- data/lib/bullet/mongoid7x.rb +57 -0
- data/lib/bullet/notification/base.rb +28 -25
- data/lib/bullet/notification/counter_cache.rb +3 -1
- data/lib/bullet/notification/n_plus_one_query.rb +8 -7
- data/lib/bullet/notification/unused_eager_loading.rb +8 -7
- data/lib/bullet/notification.rb +4 -1
- data/lib/bullet/notification_collector.rb +2 -1
- data/lib/bullet/rack.rb +66 -35
- 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 +50 -20
- data/lib/bullet/version.rb +3 -2
- data/lib/bullet.rb +136 -55
- data/lib/generators/bullet/install_generator.rb +48 -0
- data/perf/benchmark.rb +19 -22
- data/rails/init.rb +2 -0
- data/spec/bullet/detector/association_spec.rb +6 -4
- data/spec/bullet/detector/base_spec.rb +2 -0
- data/spec/bullet/detector/counter_cache_spec.rb +17 -15
- data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
- data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
- data/spec/bullet/ext/object_spec.rb +18 -11
- data/spec/bullet/ext/string_spec.rb +7 -5
- data/spec/bullet/notification/base_spec.rb +38 -39
- data/spec/bullet/notification/counter_cache_spec.rb +5 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
- data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
- data/spec/bullet/notification_collector_spec.rb +12 -10
- data/spec/bullet/rack_spec.rb +200 -48
- data/spec/bullet/registry/association_spec.rb +12 -10
- data/spec/bullet/registry/base_spec.rb +22 -20
- data/spec/bullet/registry/object_spec.rb +6 -4
- data/spec/bullet_spec.rb +64 -33
- data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
- data/spec/integration/counter_cache_spec.rb +26 -44
- data/spec/integration/mongoid/association_spec.rb +53 -65
- data/spec/models/address.rb +2 -0
- data/spec/models/attachment.rb +5 -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 +3 -1
- data/spec/models/company.rb +2 -0
- data/spec/models/country.rb +2 -0
- data/spec/models/deal.rb +5 -0
- data/spec/models/document.rb +4 -2
- 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 +3 -1
- 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 +19 -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 +3 -0
- data/spec/models/teacher.rb +2 -0
- data/spec/models/user.rb +3 -0
- data/spec/models/writer.rb +2 -0
- data/spec/spec_helper.rb +19 -23
- data/spec/support/bullet_ext.rb +10 -9
- data/spec/support/mongo_seed.rb +38 -57
- data/spec/support/rack_double.rb +13 -19
- data/spec/support/sqlite_seed.rb +104 -76
- data/tasks/bullet_tasks.rake +4 -2
- data/test.sh +5 -0
- data/update.sh +3 -0
- metadata +34 -17
- data/.travis.yml +0 -16
- data/spec/integration/active_record5/association_spec.rb +0 -768
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b21c2c4ca3caf6c41961a7182a5c8d37f6b89aa78b8dfb7badfb940f11a23191
|
|
4
|
+
data.tar.gz: 0f432034f9b4cb2fe6c6572481c797aefcfa69373839fbd0985a7efd2a0bbea9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d2457987f11f034fa457030cf7161d7508fb26230cf9e88a2571c54a934ad9a1330b48dd3d38eede3033bd7ef6c920e564dcbfa43a15354bf72d14ed799aefe2
|
|
7
|
+
data.tar.gz: ed6690fcb3bd778d6d5a27538a0ee78d298c749be1e445c305b9884448ca13f97e5a62c76ac48229a250041bb09ba609d6b154b12cf42a0f3dca66fbb9c83021
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: CI
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ master ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ master ]
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test_rails_4:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
strategy:
|
|
20
|
+
matrix:
|
|
21
|
+
gemfile: ['Gemfile.rails-4.0', 'Gemfile.rails-4.1', 'Gemfile.rails-4.2']
|
|
22
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
|
23
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v2
|
|
26
|
+
- name: Set up Ruby
|
|
27
|
+
uses: ruby/setup-ruby@v1
|
|
28
|
+
with:
|
|
29
|
+
ruby-version: 2.3
|
|
30
|
+
bundler: 1
|
|
31
|
+
bundler-cache: true
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: bundle exec rake
|
|
34
|
+
test_rails_5:
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
strategy:
|
|
37
|
+
matrix:
|
|
38
|
+
gemfile: ['Gemfile.rails-5.0', 'Gemfile.rails-5.1', 'Gemfile.rails-5.2']
|
|
39
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
|
40
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/checkout@v2
|
|
43
|
+
- name: Set up Ruby
|
|
44
|
+
uses: ruby/setup-ruby@v1
|
|
45
|
+
with:
|
|
46
|
+
ruby-version: 2.5
|
|
47
|
+
bundler: 1
|
|
48
|
+
bundler-cache: true
|
|
49
|
+
- name: Run tests
|
|
50
|
+
run: bundle exec rake
|
|
51
|
+
test_rails_6:
|
|
52
|
+
runs-on: ubuntu-latest
|
|
53
|
+
strategy:
|
|
54
|
+
matrix:
|
|
55
|
+
gemfile: ['Gemfile.rails-6.0', 'Gemfile.rails-6.1']
|
|
56
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
|
57
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/checkout@v2
|
|
60
|
+
- name: Set up Ruby
|
|
61
|
+
uses: ruby/setup-ruby@v1
|
|
62
|
+
with:
|
|
63
|
+
ruby-version: 2.7
|
|
64
|
+
bundler-cache: true
|
|
65
|
+
- name: Run tests
|
|
66
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,86 @@
|
|
|
1
|
-
|
|
1
|
+
## Next Release
|
|
2
|
+
|
|
3
|
+
## 6.1.5 (08/16/2021)
|
|
4
|
+
|
|
5
|
+
* Rename whitelist to safelist
|
|
6
|
+
* Fix onload called twice
|
|
7
|
+
* Support Rack::Files::Iterator responses
|
|
8
|
+
* Ensure HABTM associations are not incorrectly labeled n+1
|
|
9
|
+
|
|
10
|
+
## 6.1.4 (02/26/2021)
|
|
11
|
+
|
|
12
|
+
* Added an option to stop adding HTTP headers to API requests
|
|
13
|
+
|
|
14
|
+
## 6.1.3 (01/21/2021)
|
|
15
|
+
|
|
16
|
+
* Consider ThroughAssociation at SingularAssociation like CollectionAssociation
|
|
17
|
+
* Add xhr_script only when add_footer is enabled
|
|
18
|
+
|
|
19
|
+
## 6.1.2 (12/12/2020)
|
|
20
|
+
|
|
21
|
+
* Revert "Make whitelist thread safe"
|
|
22
|
+
|
|
23
|
+
## 6.1.1 (12/12/2020)
|
|
24
|
+
|
|
25
|
+
* Add support Rails 6.1
|
|
26
|
+
* Make whitelist thread safe
|
|
27
|
+
|
|
28
|
+
## 6.1.0 (12/28/2019)
|
|
29
|
+
|
|
30
|
+
* Add skip_html_injection flag
|
|
31
|
+
* Remove writer hack in active_record6
|
|
32
|
+
* Use modern includes syntax in warnings
|
|
33
|
+
* Fix warning: The last argument is used as the keyword parameter
|
|
34
|
+
|
|
35
|
+
## 6.0.2 (08/20/2019)
|
|
36
|
+
|
|
37
|
+
* Fully support Rails 6.0
|
|
38
|
+
|
|
39
|
+
## 6.0.1 (06/26/2019)
|
|
40
|
+
|
|
41
|
+
* Add Bullet::ActiveJob
|
|
42
|
+
* Prevent "Maximum call stack exceeded" errors when used with Turbolinks
|
|
43
|
+
|
|
44
|
+
## 6.0.0 (04/25/2019)
|
|
45
|
+
|
|
46
|
+
* Add XHR support to Bullet
|
|
47
|
+
* Support Rails 6.0
|
|
48
|
+
* Handle case where ID is manually set on unpersisted record
|
|
49
|
+
|
|
50
|
+
## 5.9.0 (11/11/2018)
|
|
51
|
+
|
|
52
|
+
* Require Ruby 2.3+
|
|
53
|
+
* Support Mongo 7.x
|
|
54
|
+
|
|
55
|
+
## 5.8.0 (10/29/2018)
|
|
56
|
+
|
|
57
|
+
* Fix through reflection for rails 5.x
|
|
58
|
+
* Fix false positive in after_save/after_create callbacks
|
|
59
|
+
* Don't triger a preload error on "manual" preloads
|
|
60
|
+
* Avoid Bullet from making extra queries in mongoid6
|
|
61
|
+
* Support option for #first and #last on mongoid6.x
|
|
62
|
+
* Fix duplicate logs in mongoid 4.x and 5.x version
|
|
63
|
+
* Use caller for ruby 1.9 while caller_locations for 2.0+
|
|
64
|
+
* Extend stacktrace matching for sub-file precision
|
|
65
|
+
* Exclude configured bundler path in addition to '/vendor'
|
|
66
|
+
* Fix `caller_path` in `excluded_stacktrace_path`
|
|
67
|
+
* Update `uniform_notifier` dependency to add Sentry support
|
|
68
|
+
* Integrate awesomecode.io and refactor code
|
|
69
|
+
|
|
70
|
+
## 5.7.0 (12/03/2017)
|
|
71
|
+
|
|
72
|
+
* Support rails 5.2
|
|
73
|
+
* Implement Bullet.delete_whitelist to delete a specific whitelist definition
|
|
74
|
+
* Fix caller_path in the case of nil
|
|
75
|
+
|
|
76
|
+
## 5.6.0 (07/16/2017)
|
|
77
|
+
|
|
78
|
+
* Migrate alias_method to Module#prepend
|
|
79
|
+
* Add install generator
|
|
80
|
+
* Stack trace filter
|
|
81
|
+
* Fix rails 5.1 compatibility
|
|
82
|
+
* Fix inverse_of for rails 5
|
|
83
|
+
* Fix detect file attachment for rack #319
|
|
2
84
|
|
|
3
85
|
## 5.5.0 (12/30/2016)
|
|
4
86
|
|
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-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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 5.1.0'
|
|
6
|
+
gem 'sqlite3', '~> 1.3.6'
|
|
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/Gemfile.rails-5.2
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 5.2.0'
|
|
6
|
+
gem 'sqlite3', '~> 1.3.6'
|
|
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/Gemfile.rails-6.0
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 6.0.0'
|
|
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/Gemfile.rails-6.1
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 6.1.0'
|
|
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,8 +1,8 @@
|
|
|
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
|
-
watch('spec/spec_helper.rb') {
|
|
7
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
|
8
8
|
end
|
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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Bullet
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
4
|
+
[](http://badge.fury.io/rb/bullet)
|
|
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.
|
|
@@ -13,7 +13,7 @@ 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,
|
|
16
|
+
If you use activerecord 3.x, please use bullet < 5.5.0
|
|
17
17
|
|
|
18
18
|
## External Introduction
|
|
19
19
|
|
|
@@ -34,9 +34,16 @@ or add it into a Gemfile (Bundler):
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
```ruby
|
|
37
|
-
gem
|
|
37
|
+
gem 'bullet', group: 'development'
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
enable the Bullet gem with generate command
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
bundle exec rails g bullet:install
|
|
44
|
+
```
|
|
45
|
+
The generate command will auto generate the default configuration and may ask to include in the test environment as well. See below for custom configuration.
|
|
46
|
+
|
|
40
47
|
**Note**: make sure `bullet` gem is added after activerecord (rails) and
|
|
41
48
|
mongoid.
|
|
42
49
|
|
|
@@ -48,6 +55,7 @@ Bullet won't do ANYTHING unless you tell it to explicitly. Append to
|
|
|
48
55
|
```ruby
|
|
49
56
|
config.after_initialize do
|
|
50
57
|
Bullet.enable = true
|
|
58
|
+
Bullet.sentry = true
|
|
51
59
|
Bullet.alert = true
|
|
52
60
|
Bullet.bullet_logger = true
|
|
53
61
|
Bullet.console = true
|
|
@@ -59,34 +67,43 @@ config.after_initialize do
|
|
|
59
67
|
Bullet.rails_logger = true
|
|
60
68
|
Bullet.honeybadger = true
|
|
61
69
|
Bullet.bugsnag = true
|
|
70
|
+
Bullet.appsignal = true
|
|
62
71
|
Bullet.airbrake = true
|
|
63
72
|
Bullet.rollbar = true
|
|
64
73
|
Bullet.add_footer = true
|
|
74
|
+
Bullet.skip_html_injection = false
|
|
65
75
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
|
66
|
-
Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
|
|
76
|
+
Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
|
|
67
77
|
Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
|
|
68
78
|
end
|
|
69
79
|
```
|
|
70
80
|
|
|
71
81
|
The notifier of Bullet is a wrap of [uniform_notifier](https://github.com/flyerhzm/uniform_notifier)
|
|
72
82
|
|
|
73
|
-
The code above will enable all
|
|
83
|
+
The code above will enable all of the Bullet notification systems:
|
|
74
84
|
* `Bullet.enable`: enable Bullet gem, otherwise do nothing
|
|
75
85
|
* `Bullet.alert`: pop up a JavaScript alert in the browser
|
|
76
86
|
* `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
|
|
87
|
+
* `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
|
88
|
+
* `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
89
|
+
* `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.
|
|
77
90
|
* `Bullet.rails_logger`: add warnings directly to the Rails log
|
|
78
91
|
* `Bullet.honeybadger`: add notifications to Honeybadger
|
|
79
92
|
* `Bullet.bugsnag`: add notifications to bugsnag
|
|
80
93
|
* `Bullet.airbrake`: add notifications to airbrake
|
|
94
|
+
* `Bullet.appsignal`: add notifications to AppSignal
|
|
81
95
|
* `Bullet.rollbar`: add notifications to rollbar
|
|
82
|
-
* `Bullet.
|
|
83
|
-
* `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
84
|
-
* `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.
|
|
85
|
-
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
|
96
|
+
* `Bullet.sentry`: add notifications to sentry
|
|
86
97
|
* `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.
|
|
98
|
+
* `Bullet.skip_html_injection`: prevents Bullet from injecting code into the returned HTML. This must be false for receiving alerts, showing the footer or console logging.
|
|
99
|
+
* `Bullet.skip_http_headers`: don't add headers to API requests, and remove the javascript that relies on them. Note that this prevents bullet from logging warnings to the browser console or updating the footer.
|
|
87
100
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
|
88
101
|
* `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
|
|
102
|
+
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
|
|
103
|
+
item is a line number, a Range of line numbers, or a (bare) method name, to exclude only particular lines in a file.
|
|
89
104
|
* `Bullet.slack`: add notifications to slack
|
|
105
|
+
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
|
106
|
+
|
|
90
107
|
|
|
91
108
|
Bullet also allows you to disable any of its detectors.
|
|
92
109
|
|
|
@@ -104,15 +121,15 @@ Bullet.unused_eager_loading_enable = false
|
|
|
104
121
|
Bullet.counter_cache_enable = false
|
|
105
122
|
```
|
|
106
123
|
|
|
107
|
-
##
|
|
124
|
+
## Safe list
|
|
108
125
|
|
|
109
126
|
Sometimes Bullet may notify you of query problems you don't care to fix, or
|
|
110
|
-
which come from outside your code. You can
|
|
127
|
+
which come from outside your code. You can add them to a safe list to ignore them:
|
|
111
128
|
|
|
112
129
|
```ruby
|
|
113
|
-
Bullet.
|
|
114
|
-
Bullet.
|
|
115
|
-
Bullet.
|
|
130
|
+
Bullet.add_safelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments
|
|
131
|
+
Bullet.add_safelist :type => :unused_eager_loading, :class_name => "Post", :association => :comments
|
|
132
|
+
Bullet.add_safelist :type => :counter_cache, :class_name => "Country", :association => :cities
|
|
116
133
|
```
|
|
117
134
|
|
|
118
135
|
If you want to skip bullet in some specific controller actions, you can
|
|
@@ -120,13 +137,14 @@ do like
|
|
|
120
137
|
|
|
121
138
|
```ruby
|
|
122
139
|
class ApplicationController < ActionController::Base
|
|
123
|
-
around_action :skip_bullet
|
|
140
|
+
around_action :skip_bullet, if: -> { defined?(Bullet) }
|
|
124
141
|
|
|
125
142
|
def skip_bullet
|
|
143
|
+
previous_value = Bullet.enable?
|
|
126
144
|
Bullet.enable = false
|
|
127
145
|
yield
|
|
128
146
|
ensure
|
|
129
|
-
Bullet.enable =
|
|
147
|
+
Bullet.enable = previous_value
|
|
130
148
|
end
|
|
131
149
|
end
|
|
132
150
|
```
|
|
@@ -175,15 +193,27 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
|
|
|
175
193
|
|
|
176
194
|
## Advanced
|
|
177
195
|
|
|
178
|
-
###
|
|
196
|
+
### Work with ActiveJob
|
|
179
197
|
|
|
180
|
-
|
|
198
|
+
Include `Bullet::ActiveJob` in your `ApplicationJob`.
|
|
181
199
|
|
|
182
200
|
```ruby
|
|
183
|
-
|
|
184
|
-
|
|
201
|
+
class ApplicationJob < ActiveJob::Base
|
|
202
|
+
include Bullet::ActiveJob if Rails.env.development?
|
|
203
|
+
end
|
|
204
|
+
```
|
|
185
205
|
|
|
186
|
-
|
|
206
|
+
### Work with other background job solution
|
|
207
|
+
|
|
208
|
+
Use the Bullet.profile method.
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
class ApplicationJob < ActiveJob::Base
|
|
212
|
+
around_perform do |_job, block|
|
|
213
|
+
Bullet.profile do
|
|
214
|
+
block.call
|
|
215
|
+
end
|
|
216
|
+
end
|
|
187
217
|
end
|
|
188
218
|
```
|
|
189
219
|
|
|
@@ -215,7 +245,7 @@ end
|
|
|
215
245
|
Then wrap each test in Bullet api.
|
|
216
246
|
|
|
217
247
|
```ruby
|
|
218
|
-
# spec/
|
|
248
|
+
# spec/rails_helper.rb
|
|
219
249
|
if Bullet.enable?
|
|
220
250
|
config.before(:each) do
|
|
221
251
|
Bullet.start_request
|
|
@@ -302,19 +332,10 @@ And run
|
|
|
302
332
|
bundle install
|
|
303
333
|
```
|
|
304
334
|
|
|
305
|
-
6\. enable the Bullet gem
|
|
306
|
-
`config/environments/development.rb`
|
|
335
|
+
6\. enable the Bullet gem with generate command
|
|
307
336
|
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
Bullet.enable = true
|
|
311
|
-
Bullet.alert = true
|
|
312
|
-
Bullet.bullet_logger = true
|
|
313
|
-
Bullet.console = true
|
|
314
|
-
# Bullet.growl = true
|
|
315
|
-
Bullet.rails_logger = true
|
|
316
|
-
Bullet.add_footer = true
|
|
317
|
-
end
|
|
337
|
+
```
|
|
338
|
+
bundle exec rails g bullet:install
|
|
318
339
|
```
|
|
319
340
|
|
|
320
341
|
7\. Start the server
|
|
@@ -461,4 +482,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
|
|
|
461
482
|
Post => [:comments]
|
|
462
483
|
```
|
|
463
484
|
|
|
464
|
-
Copyright (c) 2009 -
|
|
485
|
+
Copyright (c) 2009 - 2019 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/Rakefile
CHANGED
|
@@ -1,52 +1,51 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(
|
|
2
|
-
require
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
|
2
|
+
require 'bundler'
|
|
3
3
|
Bundler.setup
|
|
4
4
|
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
5
|
+
require 'rake'
|
|
6
|
+
require 'rspec'
|
|
7
|
+
require 'rspec/core/rake_task'
|
|
8
8
|
|
|
9
|
-
require
|
|
9
|
+
require 'bullet/version'
|
|
10
10
|
|
|
11
11
|
task :build do
|
|
12
|
-
system
|
|
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
|
-
puts
|
|
23
|
-
system
|
|
24
|
-
puts
|
|
22
|
+
puts 'Pushing to Github...'
|
|
23
|
+
system 'git push --tags'
|
|
24
|
+
puts 'Pushing to rubygems.org...'
|
|
25
25
|
system "gem push bullet-#{Bullet::VERSION}.gem"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
29
|
-
spec.pattern =
|
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
RSpec::Core::RakeTask.new('spec:progress') do |spec|
|
|
33
|
-
spec.rspec_opts = %w
|
|
34
|
-
spec.pattern =
|
|
33
|
+
spec.rspec_opts = %w[--format progress]
|
|
34
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
38
37
|
begin
|
|
39
38
|
require 'rdoc/task'
|
|
40
39
|
|
|
41
|
-
desc
|
|
40
|
+
desc 'Generate documentation for the plugin.'
|
|
42
41
|
Rake::RDocTask.new do |rdoc|
|
|
43
|
-
rdoc.rdoc_dir =
|
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
44
43
|
rdoc.title = "bullet #{Bullet::VERSION}"
|
|
45
|
-
rdoc.rdoc_files.include(
|
|
46
|
-
rdoc.rdoc_files.include(
|
|
44
|
+
rdoc.rdoc_files.include('README*')
|
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
47
46
|
end
|
|
48
47
|
rescue LoadError
|
|
49
48
|
puts 'RDocTask is not supported for this platform'
|
|
50
49
|
end
|
|
51
50
|
|
|
52
|
-
task :
|
|
51
|
+
task default: :spec
|
data/bullet.gemspec
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
$:.unshift lib unless $:.include?(lib)
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
|
5
|
+
|
|
6
|
+
require 'bullet/version'
|
|
5
7
|
|
|
6
8
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
9
|
+
s.name = 'bullet'
|
|
8
10
|
s.version = Bullet::VERSION
|
|
9
11
|
s.platform = Gem::Platform::RUBY
|
|
10
|
-
s.authors = [
|
|
11
|
-
s.email = [
|
|
12
|
-
s.homepage =
|
|
13
|
-
s.summary =
|
|
14
|
-
s.description =
|
|
12
|
+
s.authors = ['Richard Huang']
|
|
13
|
+
s.email = ['flyerhzm@gmail.com']
|
|
14
|
+
s.homepage = 'https://github.com/flyerhzm/bullet'
|
|
15
|
+
s.summary = 'help to kill N+1 queries and unused eager loading.'
|
|
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
|
|
|
18
|
-
s.
|
|
24
|
+
s.required_ruby_version = '>= 2.3'
|
|
25
|
+
s.required_rubygems_version = '>= 1.3.6'
|
|
19
26
|
|
|
20
|
-
s.add_runtime_dependency
|
|
21
|
-
s.add_runtime_dependency
|
|
27
|
+
s.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
|
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
|
-
s.require_paths = [
|
|
32
|
+
s.require_paths = ['lib']
|
|
26
33
|
end
|
|
27
|
-
|