bullet 5.7.0 → 5.8.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 +4 -4
- data/CHANGELOG.md +16 -1
- data/Gemfile.rails-5.2 +1 -1
- data/Guardfile +1 -1
- data/README.md +9 -4
- data/Rakefile +5 -5
- data/bullet.gemspec +11 -6
- data/lib/bullet/active_record4.rb +18 -14
- data/lib/bullet/active_record41.rb +16 -14
- data/lib/bullet/active_record42.rb +24 -22
- data/lib/bullet/active_record5.rb +78 -49
- data/lib/bullet/active_record52.rb +47 -40
- data/lib/bullet/dependency.rb +3 -1
- data/lib/bullet/detector/association.rb +16 -14
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +10 -7
- data/lib/bullet/detector/n_plus_one_query.rb +17 -15
- data/lib/bullet/detector/unused_eager_loading.rb +26 -21
- data/lib/bullet/detector.rb +2 -0
- data/lib/bullet/ext/object.rb +6 -4
- 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/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 +19 -15
- 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 +56 -19
- data/lib/bullet/version.rb +2 -1
- data/lib/bullet.rb +31 -29
- 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 +3 -1
- 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 +10 -9
- 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 +79 -17
- data/spec/integration/counter_cache_spec.rb +4 -2
- 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
- metadata +11 -7
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module Notification
|
|
3
5
|
class Base
|
|
@@ -11,11 +13,11 @@ module Bullet
|
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def title
|
|
14
|
-
raise NoMethodError
|
|
16
|
+
raise NoMethodError, 'no method title defined'
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def body
|
|
18
|
-
raise NoMethodError
|
|
20
|
+
raise NoMethodError, 'no method body defined'
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def call_stack_messages
|
|
@@ -23,7 +25,11 @@ module Bullet
|
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def whoami
|
|
26
|
-
@user ||= ENV['USER'].presence || (
|
|
28
|
+
@user ||= ENV['USER'].presence || (begin
|
|
29
|
+
`whoami`.chomp
|
|
30
|
+
rescue StandardError
|
|
31
|
+
''
|
|
32
|
+
end)
|
|
27
33
|
if @user.present?
|
|
28
34
|
"user: #{@user}"
|
|
29
35
|
else
|
|
@@ -36,11 +42,11 @@ module Bullet
|
|
|
36
42
|
end
|
|
37
43
|
|
|
38
44
|
def notify_inline
|
|
39
|
-
|
|
45
|
+
notifier.inline_notify(notification_data)
|
|
40
46
|
end
|
|
41
47
|
|
|
42
48
|
def notify_out_of_channel
|
|
43
|
-
|
|
49
|
+
notifier.out_of_channel_notify(notification_data)
|
|
44
50
|
end
|
|
45
51
|
|
|
46
52
|
def short_notice
|
|
@@ -49,10 +55,10 @@ module Bullet
|
|
|
49
55
|
|
|
50
56
|
def notification_data
|
|
51
57
|
{
|
|
52
|
-
:
|
|
53
|
-
:
|
|
54
|
-
:
|
|
55
|
-
:
|
|
58
|
+
user: whoami,
|
|
59
|
+
url: url,
|
|
60
|
+
title: title,
|
|
61
|
+
body: body_with_caller
|
|
56
62
|
}
|
|
57
63
|
end
|
|
58
64
|
|
|
@@ -66,13 +72,13 @@ module Bullet
|
|
|
66
72
|
|
|
67
73
|
protected
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
def klazz_associations_str
|
|
76
|
+
" #{@base_class} => [#{@associations.map(&:inspect).join(', ')}]"
|
|
77
|
+
end
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
def associations_str
|
|
80
|
+
":includes => #{@associations.map { |a| a.to_s.to_sym unless a.is_a? Hash }.inspect}"
|
|
81
|
+
end
|
|
76
82
|
end
|
|
77
83
|
end
|
|
78
84
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module Notification
|
|
3
5
|
class NPlusOneQuery < Base
|
|
@@ -17,15 +19,15 @@ module Bullet
|
|
|
17
19
|
|
|
18
20
|
def notification_data
|
|
19
21
|
super.merge(
|
|
20
|
-
:
|
|
22
|
+
backtrace: []
|
|
21
23
|
)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
protected
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
def call_stack_messages
|
|
29
|
+
(['Call stack'] + @callers).join("\n ")
|
|
30
|
+
end
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module Notification
|
|
3
5
|
class UnusedEagerLoading < Base
|
|
@@ -17,15 +19,15 @@ module Bullet
|
|
|
17
19
|
|
|
18
20
|
def notification_data
|
|
19
21
|
super.merge(
|
|
20
|
-
|
|
22
|
+
backtrace: []
|
|
21
23
|
)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
protected
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
def call_stack_messages
|
|
29
|
+
(['Call stack'] + @callers).join("\n ")
|
|
30
|
+
end
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
data/lib/bullet/notification.rb
CHANGED
data/lib/bullet/rack.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
class Rack
|
|
3
5
|
include Dependency
|
|
@@ -8,16 +10,17 @@ module Bullet
|
|
|
8
10
|
|
|
9
11
|
def call(env)
|
|
10
12
|
return @app.call(env) unless Bullet.enable?
|
|
13
|
+
|
|
11
14
|
Bullet.start_request
|
|
12
15
|
status, headers, response = @app.call(env)
|
|
13
16
|
|
|
14
17
|
response_body = nil
|
|
15
18
|
if Bullet.notification?
|
|
16
19
|
if !file?(headers) && !sse?(headers) && !empty?(response) &&
|
|
17
|
-
status == 200 &&
|
|
20
|
+
status == 200 && html_request?(headers, response)
|
|
18
21
|
response_body = response_body(response)
|
|
19
|
-
append_to_html_body(response_body, footer_note) if Bullet.add_footer
|
|
20
|
-
append_to_html_body(response_body, Bullet.gather_inline_notifications)
|
|
22
|
+
response_body = append_to_html_body(response_body, footer_note) if Bullet.add_footer
|
|
23
|
+
response_body = append_to_html_body(response_body, Bullet.gather_inline_notifications)
|
|
21
24
|
headers['Content-Length'] = response_body.bytesize.to_s
|
|
22
25
|
end
|
|
23
26
|
Bullet.perform_out_of_channel_notifications(env)
|
|
@@ -42,11 +45,12 @@ module Bullet
|
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
def append_to_html_body(response_body, content)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
body = response_body.dup
|
|
49
|
+
if body.include?('</body>')
|
|
50
|
+
position = body.rindex('</body>')
|
|
51
|
+
body.insert(position, content)
|
|
48
52
|
else
|
|
49
|
-
|
|
53
|
+
body << content
|
|
50
54
|
end
|
|
51
55
|
end
|
|
52
56
|
|
|
@@ -63,7 +67,7 @@ module Bullet
|
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
def html_request?(headers, response)
|
|
66
|
-
headers['Content-Type']
|
|
70
|
+
headers['Content-Type']&.include?('text/html') && response_body(response).include?('<html')
|
|
67
71
|
end
|
|
68
72
|
|
|
69
73
|
def response_body(response)
|
|
@@ -77,13 +81,13 @@ module Bullet
|
|
|
77
81
|
private
|
|
78
82
|
|
|
79
83
|
def footer_div_attributes
|
|
80
|
-
|
|
81
|
-
data-is-bullet-footer ondblclick="this.parentNode.removeChild(this);" style="position: fixed; bottom: 0pt; left: 0pt; cursor: pointer; border-style: solid; border-color: rgb(153, 153, 153);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
EOF
|
|
84
|
+
<<~EOF
|
|
85
|
+
data-is-bullet-footer ondblclick="this.parentNode.removeChild(this);" style="position: fixed; bottom: 0pt; left: 0pt; cursor: pointer; border-style: solid; border-color: rgb(153, 153, 153);
|
|
86
|
+
-moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
|
|
87
|
+
-moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
|
|
88
|
+
padding: 3px 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
|
|
89
|
+
color: rgb(119, 119, 119); font-size: 16px; font-family: 'Arial', sans-serif; z-index:9999;"
|
|
90
|
+
EOF
|
|
87
91
|
end
|
|
88
92
|
|
|
89
93
|
def footer_close_button
|
data/lib/bullet/registry/base.rb
CHANGED
data/lib/bullet/registry.rb
CHANGED
|
@@ -1,35 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module StackTraceFilter
|
|
3
|
-
VENDOR_PATH = '/vendor'
|
|
5
|
+
VENDOR_PATH = '/vendor'
|
|
4
6
|
|
|
5
7
|
def caller_in_project
|
|
6
8
|
app_root = rails? ? Rails.root.to_s : Dir.pwd
|
|
7
9
|
vendor_root = app_root + VENDOR_PATH
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
caller_path
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
when String
|
|
14
|
-
caller_path.include?(include_pattern)
|
|
15
|
-
when Regexp
|
|
16
|
-
caller_path =~ include_pattern
|
|
17
|
-
end
|
|
18
|
-
end
|
|
10
|
+
bundler_path = Bundler.bundle_path.to_s
|
|
11
|
+
select_caller_locations do |location|
|
|
12
|
+
caller_path = location_as_path(location)
|
|
13
|
+
caller_path.include?(app_root) && !caller_path.include?(vendor_root) && !caller_path.include?(bundler_path) ||
|
|
14
|
+
Bullet.stacktrace_includes.any? { |include_pattern| pattern_matches?(location, include_pattern) }
|
|
19
15
|
end
|
|
20
16
|
end
|
|
21
17
|
|
|
22
18
|
def excluded_stacktrace_path?
|
|
23
19
|
Bullet.stacktrace_excludes.any? do |exclude_pattern|
|
|
24
|
-
caller_in_project.any?
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
caller_in_project.any? { |location| pattern_matches?(location, exclude_pattern) }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def pattern_matches?(location, pattern)
|
|
27
|
+
path = location_as_path(location)
|
|
28
|
+
case pattern
|
|
29
|
+
when Array
|
|
30
|
+
pattern_path = pattern.first
|
|
31
|
+
filter = pattern.last
|
|
32
|
+
return false unless pattern_matches?(location, pattern_path)
|
|
33
|
+
|
|
34
|
+
case filter
|
|
35
|
+
when Range
|
|
36
|
+
filter.include?(location.lineno)
|
|
37
|
+
when Integer
|
|
38
|
+
filter == location.lineno
|
|
39
|
+
when String
|
|
40
|
+
filter == location.base_label
|
|
31
41
|
end
|
|
42
|
+
when String
|
|
43
|
+
path.include?(pattern)
|
|
44
|
+
when Regexp
|
|
45
|
+
path =~ pattern
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def location_as_path(location)
|
|
50
|
+
ruby_19? ? location : location.absolute_path.to_s
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def select_caller_locations
|
|
54
|
+
if ruby_19?
|
|
55
|
+
caller.select do |caller_path|
|
|
56
|
+
yield caller_path
|
|
57
|
+
end
|
|
58
|
+
else
|
|
59
|
+
caller_locations.select do |location|
|
|
60
|
+
yield location
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def ruby_19?
|
|
66
|
+
if @ruby_19.nil?
|
|
67
|
+
@ruby_19 = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
|
|
32
68
|
end
|
|
69
|
+
@ruby_19
|
|
33
70
|
end
|
|
34
71
|
end
|
|
35
72
|
end
|
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'active_support/core_ext/module/delegation'
|
|
2
4
|
require 'set'
|
|
3
5
|
require 'uniform_notifier'
|
|
@@ -17,8 +19,8 @@ module Bullet
|
|
|
17
19
|
autoload :Registry, 'bullet/registry'
|
|
18
20
|
autoload :NotificationCollector, 'bullet/notification_collector'
|
|
19
21
|
|
|
20
|
-
BULLET_DEBUG = 'BULLET_DEBUG'
|
|
21
|
-
TRUE = 'true'
|
|
22
|
+
BULLET_DEBUG = 'BULLET_DEBUG'
|
|
23
|
+
TRUE = 'true'
|
|
22
24
|
|
|
23
25
|
if defined? Rails::Railtie
|
|
24
26
|
class BulletRailtie < Rails::Railtie
|
|
@@ -29,21 +31,21 @@ module Bullet
|
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
class << self
|
|
32
|
-
attr_writer :
|
|
33
|
-
attr_reader :
|
|
34
|
+
attr_writer :n_plus_one_query_enable, :unused_eager_loading_enable, :counter_cache_enable, :stacktrace_includes, :stacktrace_excludes
|
|
35
|
+
attr_reader :whitelist
|
|
34
36
|
attr_accessor :add_footer, :orm_pathches_applied
|
|
35
37
|
|
|
36
38
|
available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
|
|
37
|
-
available_notifiers << { :
|
|
38
|
-
delegate
|
|
39
|
+
available_notifiers << { to: UniformNotifier }
|
|
40
|
+
delegate(*available_notifiers)
|
|
39
41
|
|
|
40
42
|
def raise=(should_raise)
|
|
41
43
|
UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
DETECTORS = [Bullet::Detector::NPlusOneQuery,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
Bullet::Detector::UnusedEagerLoading,
|
|
48
|
+
Bullet::Detector::CounterCache].freeze
|
|
47
49
|
|
|
48
50
|
def enable=(enable)
|
|
49
51
|
@enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
|
|
@@ -62,15 +64,15 @@ module Bullet
|
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def n_plus_one_query_enable?
|
|
65
|
-
|
|
67
|
+
enable? && !!@n_plus_one_query_enable
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
def unused_eager_loading_enable?
|
|
69
|
-
|
|
71
|
+
enable? && !!@unused_eager_loading_enable
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
def counter_cache_enable?
|
|
73
|
-
|
|
75
|
+
enable? && !!@counter_cache_enable
|
|
74
76
|
end
|
|
75
77
|
|
|
76
78
|
def stacktrace_includes
|
|
@@ -91,7 +93,7 @@ module Bullet
|
|
|
91
93
|
reset_whitelist
|
|
92
94
|
@whitelist[options[:type]][options[:class_name]] ||= []
|
|
93
95
|
@whitelist[options[:type]][options[:class_name]].delete(options[:association].to_sym)
|
|
94
|
-
@whitelist[options[:type]].delete_if { |
|
|
96
|
+
@whitelist[options[:type]].delete_if { |_key, val| val.empty? }
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
def get_whitelist_associations(type, class_name)
|
|
@@ -99,7 +101,7 @@ module Bullet
|
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
def reset_whitelist
|
|
102
|
-
@whitelist ||= { :
|
|
104
|
+
@whitelist ||= { n_plus_one_query: {}, unused_eager_loading: {}, counter_cache: {} }
|
|
103
105
|
end
|
|
104
106
|
|
|
105
107
|
def clear_whitelist
|
|
@@ -109,7 +111,7 @@ module Bullet
|
|
|
109
111
|
def bullet_logger=(active)
|
|
110
112
|
if active
|
|
111
113
|
require 'fileutils'
|
|
112
|
-
root_path =
|
|
114
|
+
root_path = (rails? ? Rails.root.to_s : Dir.pwd).to_s
|
|
113
115
|
FileUtils.mkdir_p(root_path + '/log')
|
|
114
116
|
bullet_log_file = File.open("#{root_path}/log/bullet.log", 'a+')
|
|
115
117
|
bullet_log_file.sync = true
|
|
@@ -161,6 +163,7 @@ module Bullet
|
|
|
161
163
|
|
|
162
164
|
def notification?
|
|
163
165
|
return unless start?
|
|
166
|
+
|
|
164
167
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
165
168
|
notification_collector.notifications_present?
|
|
166
169
|
end
|
|
@@ -190,11 +193,10 @@ module Bullet
|
|
|
190
193
|
end
|
|
191
194
|
|
|
192
195
|
def warnings
|
|
193
|
-
notification_collector.collection.
|
|
196
|
+
notification_collector.collection.each_with_object({}) do |notification, warnings|
|
|
194
197
|
warning_type = notification.class.to_s.split(':').last.tableize
|
|
195
198
|
warnings[warning_type] ||= []
|
|
196
199
|
warnings[warning_type] << notification
|
|
197
|
-
warnings
|
|
198
200
|
end
|
|
199
201
|
end
|
|
200
202
|
|
|
@@ -219,23 +221,23 @@ module Bullet
|
|
|
219
221
|
|
|
220
222
|
private
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
end
|
|
224
|
+
def for_each_active_notifier_with_notification
|
|
225
|
+
UniformNotifier.active_notifiers.each do |notifier|
|
|
226
|
+
notification_collector.collection.each do |notification|
|
|
227
|
+
notification.notifier = notifier
|
|
228
|
+
yield notification
|
|
228
229
|
end
|
|
229
230
|
end
|
|
231
|
+
end
|
|
230
232
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
+
def build_request_uri(env)
|
|
234
|
+
return "#{env['REQUEST_METHOD']} #{env['REQUEST_URI']}" if env['REQUEST_URI']
|
|
233
235
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
end
|
|
236
|
+
if env['QUERY_STRING'].present?
|
|
237
|
+
"#{env['REQUEST_METHOD']} #{env['PATH_INFO']}?#{env['QUERY_STRING']}"
|
|
238
|
+
else
|
|
239
|
+
"#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
|
|
239
240
|
end
|
|
241
|
+
end
|
|
240
242
|
end
|
|
241
243
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Bullet
|
|
2
4
|
module Generators
|
|
3
5
|
class InstallGenerator < ::Rails::Generators::Base
|
|
4
|
-
desc
|
|
5
|
-
Description:
|
|
6
|
-
|
|
6
|
+
desc <<~DESC
|
|
7
|
+
Description:
|
|
8
|
+
Enable bullet in development/test for your application.
|
|
7
9
|
DESC
|
|
8
10
|
|
|
9
11
|
def enable_in_development
|
data/perf/benchmark.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH << 'lib'
|
|
2
4
|
require 'benchmark'
|
|
3
5
|
require 'rails'
|
|
4
6
|
require 'active_record'
|
|
@@ -27,13 +29,13 @@ class User < ActiveRecord::Base
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
# create database bullet_benchmark;
|
|
30
|
-
ActiveRecord::Base.establish_connection(:
|
|
32
|
+
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'bullet_benchmark', server: '/tmp/mysql.socket', username: 'root')
|
|
31
33
|
|
|
32
34
|
ActiveRecord::Base.connection.tables.each do |table|
|
|
33
35
|
ActiveRecord::Base.connection.drop_table(table)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
ActiveRecord::Schema.define(:
|
|
38
|
+
ActiveRecord::Schema.define(version: 1) do
|
|
37
39
|
create_table :posts do |t|
|
|
38
40
|
t.column :title, :string
|
|
39
41
|
t.column :body, :string
|
|
@@ -56,21 +58,21 @@ posts_size = 1000
|
|
|
56
58
|
comments_size = 10_000
|
|
57
59
|
users = []
|
|
58
60
|
users_size.times do |i|
|
|
59
|
-
users << User.new(:
|
|
61
|
+
users << User.new(name: "user#{i}")
|
|
60
62
|
end
|
|
61
63
|
User.import users
|
|
62
64
|
users = User.all
|
|
63
65
|
|
|
64
66
|
posts = []
|
|
65
67
|
posts_size.times do |i|
|
|
66
|
-
posts << Post.new(:
|
|
68
|
+
posts << Post.new(title: "Title #{i}", body: "Body #{i}", user: users[i % 100])
|
|
67
69
|
end
|
|
68
70
|
Post.import posts
|
|
69
71
|
posts = Post.all
|
|
70
72
|
|
|
71
73
|
comments = []
|
|
72
74
|
comments_size.times do |i|
|
|
73
|
-
comments << Comment.new(:
|
|
75
|
+
comments << Comment.new(body: "Comment #{i}", post: posts[i % 1000], user: users[i % 100])
|
|
74
76
|
end
|
|
75
77
|
Comment.import comments
|
|
76
78
|
|
|
@@ -82,7 +84,7 @@ Benchmark.bm(70) do |bm|
|
|
|
82
84
|
bm.report("Querying & Iterating #{posts_size} Posts with #{comments_size} Comments and #{users_size} Users") do
|
|
83
85
|
10.times do
|
|
84
86
|
Bullet.start_request
|
|
85
|
-
Post.select('SQL_NO_CACHE *').includes(:user, :
|
|
87
|
+
Post.select('SQL_NO_CACHE *').includes(:user, comments: :user).each do |p|
|
|
86
88
|
p.title
|
|
87
89
|
p.user.name
|
|
88
90
|
p.comments.each do |c|
|
data/rails/init.rb
CHANGED