bullet 5.3.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed73722e74144833068cf4572e3624687a9db64b
4
- data.tar.gz: e882a8f5c7e4bfbe1d37254e1255ed79fc3f3948
3
+ metadata.gz: 58f4f616944a1bfde9a34e4670788802f0ccd418
4
+ data.tar.gz: 61aabed03705063018b28e1505f0f0b693e1109b
5
5
  SHA512:
6
- metadata.gz: a62b1a339dccad8b79e97971c8d7fc73f977eb9d0b1c19758f59259e85531116fb57a9ef51c90e013d6051a27616ec861380d0940f658102155a163f52eb1873
7
- data.tar.gz: de637d2bb853c67a5e7f2b269f698b18b59a481f5988025407d094e0442df03de805bc3890945e49accba76d3ae3c7a62c4185a8fde8d584550eac251a281836
6
+ metadata.gz: 4be86c6d80b67bec48ee84d491b3b92cd19f9b9ea6d6d9d7d973848f93801edf0165f9a7f8f9309d7feee84ed2da1d6f39170161da2d0b01fe8debf7724d6dc9
7
+ data.tar.gz: b82c8e8207775a8e987e52fbbddb6d35350c591df288e1152ee2d55e8de9f257ca55f82bcac02c59807b3cffa76038c0373fc09ba42c36a45be059fc05fed7e8
@@ -1,11 +1,16 @@
1
1
  # Next Release
2
2
 
3
+ ## 5.4.0 (10/09/2016)
4
+
5
+ * Support rails 5.1
6
+ * Extract stack trace filtering into module
7
+
3
8
  ## 5.3.0 (15/08/2016)
4
9
 
5
10
  * Fix false alert on through association with join sql #301
6
- * Fix association.target in through_association can be singular #302
7
- * Support find_by_sql #303
8
- * Fix env REQUEST_URI
11
+ * Fix association.target in `through_association` can be singular #302
12
+ * Support `find_by_sql` #303
13
+ * Fix env `REQUEST_URI`
9
14
 
10
15
  ## 5.2.0 (07/26/2016)
11
16
 
@@ -4,6 +4,7 @@ require 'uniform_notifier'
4
4
  require 'bullet/ext/object'
5
5
  require 'bullet/ext/string'
6
6
  require 'bullet/dependency'
7
+ require 'bullet/stack_trace_filter'
7
8
 
8
9
  module Bullet
9
10
  extend Dependency
@@ -26,6 +26,8 @@ module Bullet
26
26
  'active_record42'
27
27
  elsif active_record50?
28
28
  'active_record5'
29
+ elsif active_record51?
30
+ 'active_record5'
29
31
  end
30
32
  end
31
33
  end
@@ -84,8 +86,12 @@ module Bullet
84
86
  active_record5? && ::ActiveRecord::VERSION::MINOR == 0
85
87
  end
86
88
 
89
+ def active_record51?
90
+ active_record5? && ::ActiveRecord::VERSION::MINOR == 1
91
+ end
92
+
87
93
  def mongoid2x?
88
- mongoid? && ::Mongoid::VERSION =~ /\A2\.[4-8]/
94
+ mongoid? && ::Mongoid::VERSION =~ /\A2\.[4-9]/
89
95
  end
90
96
 
91
97
  def mongoid3x?
@@ -2,6 +2,7 @@ module Bullet
2
2
  module Detector
3
3
  class NPlusOneQuery < Association
4
4
  extend Dependency
5
+ extend StackTraceFilter
5
6
 
6
7
  class <<self
7
8
  # executed when object.assocations is called.
@@ -87,21 +88,6 @@ module Bullet
87
88
  Bullet.notification_collector.add(notice)
88
89
  end
89
90
  end
90
-
91
- def caller_in_project
92
- app_root = rails? ? Rails.root.to_s : Dir.pwd
93
- vendor_root = app_root + "/vendor"
94
- caller.select do |c|
95
- c.include?(app_root) && !c.include?(vendor_root) ||
96
- Bullet.stacktrace_includes.any? { |include| c.include?(include) }
97
- end
98
- end
99
-
100
- def excluded_stacktrace_path?
101
- Bullet.stacktrace_excludes.any? do |excluded_path|
102
- caller_in_project.any? { |c| c.include?(excluded_path) }
103
- end
104
- end
105
91
  end
106
92
  end
107
93
  end
@@ -1,6 +1,9 @@
1
1
  module Bullet
2
2
  module Detector
3
3
  class UnusedEagerLoading < Association
4
+ extend Dependency
5
+ extend StackTraceFilter
6
+
4
7
  class <<self
5
8
  # check if there are unused preload associations.
6
9
  # get related_objects from eager_loadings associated with object and associations
@@ -15,7 +18,7 @@ module Bullet
15
18
  next if object_association_diff.empty?
16
19
 
17
20
  Bullet.debug("detect unused preload", "object: #{bullet_key}, associations: #{object_association_diff}")
18
- create_notification bullet_key.bullet_class_name, object_association_diff
21
+ create_notification(caller_in_project, bullet_key.bullet_class_name, object_association_diff)
19
22
  end
20
23
  end
21
24
 
@@ -53,11 +56,11 @@ module Bullet
53
56
  end
54
57
 
55
58
  private
56
- def create_notification(klazz, associations)
59
+ def create_notification(callers, klazz, associations)
57
60
  notify_associations = Array(associations) - Bullet.get_whitelist_associations(:unused_eager_loading, klazz)
58
61
 
59
62
  if notify_associations.present?
60
- notice = Bullet::Notification::UnusedEagerLoading.new(klazz, notify_associations)
63
+ notice = Bullet::Notification::UnusedEagerLoading.new(callers, klazz, notify_associations)
61
64
  Bullet.notification_collector.add(notice)
62
65
  end
63
66
  end
@@ -1,6 +1,18 @@
1
1
  module Bullet
2
2
  module Notification
3
3
  class UnusedEagerLoading < Base
4
+ def initialize(callers, base_class, associations, path = nil)
5
+ super(base_class, associations, path)
6
+
7
+ @callers = callers
8
+ end
9
+
10
+ def notification_data
11
+ super.merge(
12
+ :backtrace => @callers
13
+ )
14
+ end
15
+
4
16
  def body
5
17
  "#{klazz_associations_str}\n Remove from your finder: #{associations_str}"
6
18
  end
@@ -80,8 +80,8 @@ module Bullet
80
80
  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);
81
81
  -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
82
82
  -moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
83
- padding: 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
84
- color: rgb(119, 119, 119); font-size: 18px; font-family: 'Arial', sans-serif; z-index:9999;"
83
+ padding: 3px 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
84
+ color: rgb(119, 119, 119); font-size: 16px; font-family: 'Arial', sans-serif; z-index:9999;"
85
85
  EOF
86
86
  end
87
87
  end
@@ -0,0 +1,34 @@
1
+ module Bullet
2
+ module StackTraceFilter
3
+ VENDOR_PATH = "/vendor"
4
+
5
+ def caller_in_project
6
+ app_root = rails? ? Rails.root.to_s : Dir.pwd
7
+ vendor_root = app_root + VENDOR_PATH
8
+ caller.select do |caller_path|
9
+ caller_path.include?(app_root) && !caller_path.include?(vendor_root) ||
10
+ Bullet.stacktrace_includes.any? do |include_pattern|
11
+ case include_pattern
12
+ when String
13
+ caller_path.include?(include_pattern)
14
+ when Regexp
15
+ caller_path =~ include_pattern
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def excluded_stacktrace_path?
22
+ Bullet.stacktrace_excludes.any? do |exclude_pattern|
23
+ caller_in_project.any? do |caller_path|
24
+ case exclude_pattern
25
+ when String
26
+ caller_path.include?(exclude_pattern)
27
+ when Regexp
28
+ caller_path =~ exclude_pattern
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "5.3.0"
3
+ VERSION = "5.4.0"
4
4
  end
@@ -87,7 +87,7 @@ module Bullet
87
87
  end
88
88
 
89
89
  context "stacktrace_excludes" do
90
- before { Bullet.stacktrace_excludes = [ 'def' ] }
90
+ before { Bullet.stacktrace_excludes = [ /def/ ] }
91
91
  after { Bullet.stacktrace_excludes = nil }
92
92
 
93
93
  it "should not create notification when stacktrace contains paths that are in the exclude list" do
@@ -114,17 +114,17 @@ module Bullet
114
114
  end
115
115
 
116
116
  context "stacktrace_includes" do
117
- before { Bullet.stacktrace_includes = [ 'def' ] }
117
+ before { Bullet.stacktrace_includes = [ 'def', /xyz/ ] }
118
118
  after { Bullet.stacktrace_includes = nil }
119
119
 
120
120
  it "should include paths that are in the stacktrace_include list" do
121
121
  in_project = File.join(Dir.pwd, 'abc', 'abc.rb')
122
- included_gem = '/def/def.rb'
122
+ included_gems = ['/def/def.rb', 'xyz/xyz.rb']
123
123
  excluded_gem = '/ghi/ghi.rb'
124
124
 
125
- expect(NPlusOneQuery).to receive(:caller).and_return([in_project, included_gem, excluded_gem])
125
+ expect(NPlusOneQuery).to receive(:caller).and_return([in_project, *included_gems, excluded_gem])
126
126
  expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(true)
127
- expect(NPlusOneQuery).to receive(:create_notification).with([in_project, included_gem], "Post", :association)
127
+ expect(NPlusOneQuery).to receive(:create_notification).with([in_project, *included_gems], "Post", :association)
128
128
  NPlusOneQuery.call_association(@post, :association)
129
129
  end
130
130
  end
@@ -39,9 +39,11 @@ module Bullet
39
39
  end
40
40
 
41
41
  context ".check_unused_preload_associations" do
42
+ let(:paths) { ["/dir1", "/dir1/subdir"] }
42
43
  it "should create notification if object_association_diff is not empty" do
43
44
  UnusedEagerLoading.add_object_associations(@post, :association)
44
- expect(UnusedEagerLoading).to receive(:create_notification).with("Post", [:association])
45
+ allow(UnusedEagerLoading).to receive(:caller_in_project).and_return(paths)
46
+ expect(UnusedEagerLoading).to receive(:create_notification).with(paths, "Post", [:association])
45
47
  UnusedEagerLoading.check_unused_preload_associations
46
48
  end
47
49
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Bullet
4
4
  module Notification
5
5
  describe UnusedEagerLoading do
6
- subject { UnusedEagerLoading.new(Post, [:comments, :votes], "path") }
6
+ subject { UnusedEagerLoading.new([""], Post, [:comments, :votes], "path") }
7
7
 
8
8
  it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Remove from your finder: :includes => [:comments, :votes]") }
9
9
  it { expect(subject.title).to eq("Unused Eager Loading in path") }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -104,6 +104,7 @@ files:
104
104
  - lib/bullet/registry/association.rb
105
105
  - lib/bullet/registry/base.rb
106
106
  - lib/bullet/registry/object.rb
107
+ - lib/bullet/stack_trace_filter.rb
107
108
  - lib/bullet/version.rb
108
109
  - perf/benchmark.rb
109
110
  - rails/init.rb