bullet 5.6.0 → 5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Guardfile +2 -2
- data/Rakefile +16 -16
- data/bullet.gemspec +11 -11
- data/lib/bullet.rb +3 -3
- data/lib/bullet/detector/association.rb +2 -2
- data/lib/bullet/detector/counter_cache.rb +3 -3
- data/lib/bullet/detector/n_plus_one_query.rb +5 -5
- data/lib/bullet/detector/unused_eager_loading.rb +2 -2
- data/lib/bullet/ext/string.rb +1 -1
- data/lib/bullet/notification/base.rb +6 -6
- data/lib/bullet/notification/counter_cache.rb +1 -1
- data/lib/bullet/rack.rb +4 -4
- data/lib/bullet/stack_trace_filter.rb +2 -2
- data/lib/bullet/version.rb +2 -2
- data/lib/generators/bullet/install_generator.rb +5 -5
- data/perf/benchmark.rb +3 -3
- data/spec/bullet/detector/association_spec.rb +4 -4
- data/spec/bullet/detector/counter_cache_spec.rb +11 -11
- data/spec/bullet/detector/n_plus_one_query_spec.rb +33 -33
- data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -19
- data/spec/bullet/ext/object_spec.rb +7 -7
- data/spec/bullet/ext/string_spec.rb +5 -5
- data/spec/bullet/notification/base_spec.rb +32 -32
- data/spec/bullet/notification/counter_cache_spec.rb +2 -2
- data/spec/bullet/notification/n_plus_one_query_spec.rb +2 -2
- data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
- data/spec/bullet/notification_collector_spec.rb +10 -10
- data/spec/bullet/rack_spec.rb +46 -46
- data/spec/bullet/registry/association_spec.rb +10 -10
- data/spec/bullet/registry/base_spec.rb +20 -20
- data/spec/bullet/registry/object_spec.rb +4 -4
- data/spec/integration/active_record/association_spec.rb +101 -101
- data/spec/integration/counter_cache_spec.rb +12 -12
- data/spec/integration/mongoid/association_spec.rb +33 -33
- data/spec/models/comment.rb +1 -1
- data/spec/models/document.rb +2 -2
- data/spec/models/mongoid/address.rb +1 -1
- data/spec/models/mongoid/category.rb +2 -2
- data/spec/models/mongoid/comment.rb +1 -1
- data/spec/models/mongoid/company.rb +1 -1
- data/spec/models/mongoid/entry.rb +1 -1
- data/spec/models/mongoid/post.rb +3 -3
- data/spec/models/newspaper.rb +1 -1
- data/spec/spec_helper.rb +12 -12
- data/spec/support/mongo_seed.rb +6 -6
- data/spec/support/rack_double.rb +2 -2
- data/spec/support/sqlite_seed.rb +6 -6
- data/tasks/bullet_tasks.rake +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32281988136558818e4c3ae98c4059d88b6baf79
|
4
|
+
data.tar.gz: eb9281de70a51206eddebfe0eb70fa681b7bff51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49d6dba2f3881bd6c129ff12b2c241627431602804010a2a09cc11e5a1912c636f75b1f286e863117426faa830a7486b17b29b37fe6aa706f241e18eb3df282e
|
7
|
+
data.tar.gz: a24b68afef28189f25406b8233d50e1b14a002d71749d4bfa85a0fff40a9d9a927140e133d2f11aaf5878b126da70544a4e335ddedb6db99ce1f1fa3b10569af
|
data/CHANGELOG.md
CHANGED
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', :version => 2, :all_after_pass => false, :all_on_start => false, :cli =>
|
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/Rakefile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(
|
2
|
-
require
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
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
15
|
task :install => :build do
|
@@ -19,31 +19,31 @@ end
|
|
19
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
33
|
spec.rspec_opts = %w(--format progress)
|
34
|
-
spec.pattern =
|
34
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
35
35
|
end
|
36
36
|
|
37
37
|
|
38
38
|
begin
|
39
39
|
require 'rdoc/task'
|
40
40
|
|
41
|
-
desc
|
41
|
+
desc 'Generate documentation for the plugin.'
|
42
42
|
Rake::RDocTask.new do |rdoc|
|
43
|
-
rdoc.rdoc_dir =
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
44
|
rdoc.title = "bullet #{Bullet::VERSION}"
|
45
|
-
rdoc.rdoc_files.include(
|
46
|
-
rdoc.rdoc_files.include(
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
47
|
end
|
48
48
|
rescue LoadError
|
49
49
|
puts 'RDocTask is not supported for this platform'
|
data/bullet.gemspec
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
lib = File.expand_path('../lib/', __FILE__)
|
2
2
|
$:.unshift lib unless $:.include?(lib)
|
3
3
|
|
4
|
-
require
|
4
|
+
require 'bullet/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
7
|
+
s.name = 'bullet'
|
8
8
|
s.version = Bullet::VERSION
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
|
-
s.authors = [
|
11
|
-
s.email = [
|
12
|
-
s.homepage =
|
13
|
-
s.summary =
|
14
|
-
s.description =
|
10
|
+
s.authors = ['Richard Huang']
|
11
|
+
s.email = ['flyerhzm@gmail.com']
|
12
|
+
s.homepage = 'http://github.com/flyerhzm/bullet'
|
13
|
+
s.summary = 'help to kill N+1 queries and unused eager loading.'
|
14
|
+
s.description = 'help to kill N+1 queries and unused eager loading.'
|
15
15
|
|
16
16
|
s.license = 'MIT'
|
17
17
|
|
18
|
-
s.required_rubygems_version =
|
18
|
+
s.required_rubygems_version = '>= 1.3.6'
|
19
19
|
|
20
|
-
s.add_runtime_dependency
|
21
|
-
s.add_runtime_dependency
|
20
|
+
s.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
21
|
+
s.add_runtime_dependency 'uniform_notifier', '~> 1.10.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")
|
25
|
-
s.require_paths = [
|
25
|
+
s.require_paths = ['lib']
|
26
26
|
end
|
27
27
|
|
data/lib/bullet.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
2
|
require 'set'
|
3
3
|
require 'uniform_notifier'
|
4
4
|
require 'bullet/ext/object'
|
@@ -22,7 +22,7 @@ module Bullet
|
|
22
22
|
|
23
23
|
if defined? Rails::Railtie
|
24
24
|
class BulletRailtie < Rails::Railtie
|
25
|
-
initializer
|
25
|
+
initializer 'bullet.configure_rails_initialization' do |app|
|
26
26
|
app.middleware.use Bullet::Rack
|
27
27
|
end
|
28
28
|
end
|
@@ -43,7 +43,7 @@ module Bullet
|
|
43
43
|
|
44
44
|
DETECTORS = [ Bullet::Detector::NPlusOneQuery,
|
45
45
|
Bullet::Detector::UnusedEagerLoading,
|
46
|
-
Bullet::Detector::CounterCache ]
|
46
|
+
Bullet::Detector::CounterCache ].freeze
|
47
47
|
|
48
48
|
def enable=(enable)
|
49
49
|
@enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
|
@@ -7,7 +7,7 @@ module Bullet
|
|
7
7
|
return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
|
8
8
|
return unless object.primary_key_value
|
9
9
|
|
10
|
-
Bullet.debug(
|
10
|
+
Bullet.debug('Detector::Association#add_object_associations'.freeze, "object: #{object.bullet_key}, associations: #{associations}")
|
11
11
|
object_associations.add(object.bullet_key, associations)
|
12
12
|
end
|
13
13
|
|
@@ -16,7 +16,7 @@ module Bullet
|
|
16
16
|
return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
|
17
17
|
return unless object.primary_key_value
|
18
18
|
|
19
|
-
Bullet.debug(
|
19
|
+
Bullet.debug('Detector::Association#add_call_object_associations'.freeze, "object: #{object.bullet_key}, associations: #{associations}")
|
20
20
|
call_object_associations.add(object.bullet_key, associations)
|
21
21
|
end
|
22
22
|
|
@@ -7,7 +7,7 @@ module Bullet
|
|
7
7
|
return unless Bullet.counter_cache_enable?
|
8
8
|
return unless object.primary_key_value
|
9
9
|
|
10
|
-
Bullet.debug(
|
10
|
+
Bullet.debug('Detector::CounterCache#add_counter_cache', "object: #{object.bullet_key}, associations: #{associations}")
|
11
11
|
if conditions_met?(object, associations)
|
12
12
|
create_notification object.class.to_s, associations
|
13
13
|
end
|
@@ -19,7 +19,7 @@ module Bullet
|
|
19
19
|
objects = Array(object_or_objects)
|
20
20
|
return if objects.map(&:primary_key_value).compact.empty?
|
21
21
|
|
22
|
-
Bullet.debug(
|
22
|
+
Bullet.debug('Detector::CounterCache#add_possible_objects', "objects: #{objects.map(&:bullet_key).join(', ')}")
|
23
23
|
objects.each { |object| possible_objects.add object.bullet_key }
|
24
24
|
end
|
25
25
|
|
@@ -28,7 +28,7 @@ module Bullet
|
|
28
28
|
return unless Bullet.counter_cache_enable?
|
29
29
|
return unless object.primary_key_value
|
30
30
|
|
31
|
-
Bullet.debug(
|
31
|
+
Bullet.debug('Detector::CounterCache#add_impossible_object', "object: #{object.bullet_key}")
|
32
32
|
impossible_objects.add object.bullet_key
|
33
33
|
end
|
34
34
|
|
@@ -16,9 +16,9 @@ module Bullet
|
|
16
16
|
return if inversed_objects.include?(object.bullet_key, associations)
|
17
17
|
add_call_object_associations(object, associations)
|
18
18
|
|
19
|
-
Bullet.debug(
|
19
|
+
Bullet.debug('Detector::NPlusOneQuery#call_association'.freeze, "object: #{object.bullet_key}, associations: #{associations}")
|
20
20
|
if !excluded_stacktrace_path? && conditions_met?(object, associations)
|
21
|
-
Bullet.debug(
|
21
|
+
Bullet.debug('detect n + 1 query', "object: #{object.bullet_key}, associations: #{associations}")
|
22
22
|
create_notification caller_in_project, object.class.to_s, associations
|
23
23
|
end
|
24
24
|
end
|
@@ -29,7 +29,7 @@ module Bullet
|
|
29
29
|
objects = Array(object_or_objects)
|
30
30
|
return if objects.map(&:primary_key_value).compact.empty?
|
31
31
|
|
32
|
-
Bullet.debug(
|
32
|
+
Bullet.debug('Detector::NPlusOneQuery#add_possible_objects'.freeze, "objects: #{objects.map(&:bullet_key).join(', '.freeze)}")
|
33
33
|
objects.each { |object| possible_objects.add object.bullet_key }
|
34
34
|
end
|
35
35
|
|
@@ -38,7 +38,7 @@ module Bullet
|
|
38
38
|
return unless Bullet.n_plus_one_query_enable?
|
39
39
|
return unless object.primary_key_value
|
40
40
|
|
41
|
-
Bullet.debug(
|
41
|
+
Bullet.debug('Detector::NPlusOneQuery#add_impossible_object'.freeze, "object: #{object.bullet_key}")
|
42
42
|
impossible_objects.add object.bullet_key
|
43
43
|
end
|
44
44
|
|
@@ -47,7 +47,7 @@ module Bullet
|
|
47
47
|
return unless Bullet.n_plus_one_query_enable?
|
48
48
|
return unless object.primary_key_value
|
49
49
|
|
50
|
-
Bullet.debug(
|
50
|
+
Bullet.debug('Detector::NPlusOneQuery#add_inversed_object'.freeze, "object: #{object.bullet_key}, association: #{association}")
|
51
51
|
inversed_objects.add object.bullet_key, association
|
52
52
|
end
|
53
53
|
|
@@ -17,7 +17,7 @@ module Bullet
|
|
17
17
|
object_association_diff = diff_object_associations bullet_key, associations
|
18
18
|
next if object_association_diff.empty?
|
19
19
|
|
20
|
-
Bullet.debug(
|
20
|
+
Bullet.debug('detect unused preload', "object: #{bullet_key}, associations: #{object_association_diff}")
|
21
21
|
create_notification(caller_in_project, bullet_key.bullet_class_name, object_association_diff)
|
22
22
|
end
|
23
23
|
end
|
@@ -27,7 +27,7 @@ module Bullet
|
|
27
27
|
return unless Bullet.unused_eager_loading_enable?
|
28
28
|
return if objects.map(&:primary_key_value).compact.empty?
|
29
29
|
|
30
|
-
Bullet.debug(
|
30
|
+
Bullet.debug('Detector::UnusedEagerLoading#add_eager_loadings', "objects: #{objects.map(&:bullet_key).join(', ')}, associations: #{associations}")
|
31
31
|
bullet_keys = objects.map(&:bullet_key)
|
32
32
|
|
33
33
|
to_add, to_merge, to_delete = [], [], []
|
data/lib/bullet/ext/string.rb
CHANGED
@@ -11,23 +11,23 @@ module Bullet
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def title
|
14
|
-
raise NoMethodError.new(
|
14
|
+
raise NoMethodError.new('no method title defined')
|
15
15
|
end
|
16
16
|
|
17
17
|
def body
|
18
|
-
raise NoMethodError.new(
|
18
|
+
raise NoMethodError.new('no method body defined')
|
19
19
|
end
|
20
20
|
|
21
21
|
def call_stack_messages
|
22
|
-
|
22
|
+
''
|
23
23
|
end
|
24
24
|
|
25
25
|
def whoami
|
26
|
-
@user ||= ENV['USER'].presence || (`whoami`.chomp rescue
|
26
|
+
@user ||= ENV['USER'].presence || (`whoami`.chomp rescue '')
|
27
27
|
if @user.present?
|
28
28
|
"user: #{@user}"
|
29
29
|
else
|
30
|
-
|
30
|
+
''
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -44,7 +44,7 @@ module Bullet
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def short_notice
|
47
|
-
[whoami.presence, url, title, body].compact.join(
|
47
|
+
[whoami.presence, url, title, body].compact.join(' ')
|
48
48
|
end
|
49
49
|
|
50
50
|
def notification_data
|
data/lib/bullet/rack.rb
CHANGED
@@ -51,19 +51,19 @@ module Bullet
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def footer_note
|
54
|
-
"<div #{footer_div_attributes}>" + footer_close_button + Bullet.footer_info.uniq.join(
|
54
|
+
"<div #{footer_div_attributes}>" + footer_close_button + Bullet.footer_info.uniq.join('<br>') + '</div>'
|
55
55
|
end
|
56
56
|
|
57
57
|
def file?(headers)
|
58
|
-
headers[
|
58
|
+
headers['Content-Transfer-Encoding'] == 'binary' || headers['Content-Disposition']
|
59
59
|
end
|
60
60
|
|
61
61
|
def sse?(headers)
|
62
|
-
headers[
|
62
|
+
headers['Content-Type'] == 'text/event-stream'
|
63
63
|
end
|
64
64
|
|
65
65
|
def html_request?(headers, response)
|
66
|
-
headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response_body(response).include?(
|
66
|
+
headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response_body(response).include?('<html')
|
67
67
|
end
|
68
68
|
|
69
69
|
def response_body(response)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Bullet
|
2
2
|
module StackTraceFilter
|
3
|
-
VENDOR_PATH =
|
3
|
+
VENDOR_PATH = '/vendor'.freeze
|
4
4
|
|
5
5
|
def caller_in_project
|
6
6
|
app_root = rails? ? Rails.root.to_s : Dir.pwd
|
7
7
|
vendor_root = app_root + VENDOR_PATH
|
8
8
|
caller_locations.select do |location|
|
9
|
-
caller_path = location.absolute_path
|
9
|
+
caller_path = location.absolute_path.to_s
|
10
10
|
caller_path.include?(app_root) && !caller_path.include?(vendor_root) ||
|
11
11
|
Bullet.stacktrace_includes.any? do |include_pattern|
|
12
12
|
case include_pattern
|
data/lib/bullet/version.rb
CHANGED
@@ -7,7 +7,7 @@ Description:
|
|
7
7
|
DESC
|
8
8
|
|
9
9
|
def enable_in_development
|
10
|
-
environment(nil, env:
|
10
|
+
environment(nil, env: 'development') do
|
11
11
|
<<-"FILE".strip
|
12
12
|
|
13
13
|
config.after_initialize do
|
@@ -22,12 +22,12 @@ Description:
|
|
22
22
|
FILE
|
23
23
|
end
|
24
24
|
|
25
|
-
say
|
25
|
+
say 'Enabled bullet in config/environments/development.rb'
|
26
26
|
end
|
27
27
|
|
28
28
|
def enable_in_test
|
29
|
-
if yes?(
|
30
|
-
environment(nil, env:
|
29
|
+
if yes?('Would you like to enable bullet in test environment? (y/n)')
|
30
|
+
environment(nil, env: 'test') do
|
31
31
|
<<-"FILE".strip
|
32
32
|
|
33
33
|
config.after_initialize do
|
@@ -38,7 +38,7 @@ Description:
|
|
38
38
|
FILE
|
39
39
|
end
|
40
40
|
|
41
|
-
say
|
41
|
+
say 'Enabled bullet in config/environments/test.rb'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
data/perf/benchmark.rb
CHANGED
@@ -74,7 +74,7 @@ comments_size.times do |i|
|
|
74
74
|
end
|
75
75
|
Comment.import comments
|
76
76
|
|
77
|
-
puts
|
77
|
+
puts 'Start benchmarking...'
|
78
78
|
|
79
79
|
|
80
80
|
Bullet.enable = true
|
@@ -83,7 +83,7 @@ Benchmark.bm(70) do |bm|
|
|
83
83
|
bm.report("Querying & Iterating #{posts_size} Posts with #{comments_size} Comments and #{users_size} Users") do
|
84
84
|
10.times do
|
85
85
|
Bullet.start_request
|
86
|
-
Post.select(
|
86
|
+
Post.select('SQL_NO_CACHE *').includes(:user, :comments => :user).each do |p|
|
87
87
|
p.title
|
88
88
|
p.user.name
|
89
89
|
p.comments.each do |c|
|
@@ -96,7 +96,7 @@ Benchmark.bm(70) do |bm|
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
puts
|
99
|
+
puts 'End benchmarking...'
|
100
100
|
|
101
101
|
|
102
102
|
# Run benchmark with bundler
|
@@ -8,15 +8,15 @@ module Bullet
|
|
8
8
|
@post2 = Post.last
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
12
|
-
it
|
11
|
+
context '.add_object_association' do
|
12
|
+
it 'should add object, associations pair' do
|
13
13
|
Association.add_object_associations(@post1, :associations)
|
14
14
|
expect(Association.send(:object_associations)).to be_include(@post1.bullet_key, :associations)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
19
|
-
it
|
18
|
+
context '.add_call_object_associations' do
|
19
|
+
it 'should add call object, associations pair' do
|
20
20
|
Association.add_call_object_associations(@post1, :associations)
|
21
21
|
expect(Association.send(:call_object_associations)).to be_include(@post1.bullet_key, :associations)
|
22
22
|
end
|