bullet 8.0.0 → 8.0.1
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 +6 -0
- data/lib/bullet/detector/association.rb +1 -1
- data/lib/bullet/detector/n_plus_one_query.rb +6 -5
- data/lib/bullet/ext/object.rb +9 -11
- data/lib/bullet/ext/string.rb +2 -1
- data/lib/bullet/stack_trace_filter.rb +2 -4
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +1 -0
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eb8c8d2264141849784cb8a103b9521a8fad5ba11eba1daa9a5a576f02c2bcc6
|
|
4
|
+
data.tar.gz: e9b5a2a2f123ad3e84007407123103535844dcde3c7e9f3da304eb019d55f96d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc9c11edab1b705ba7f51f63bf0315c94d5c3f4178684c42da4042adeef52da7570939a91556301dcb076a08a9dc816b89cd38c8a5399c7a8fe81baf2562ca01
|
|
7
|
+
data.tar.gz: aa0cc8a93443e8fa17582ac89dca1eba8714080ebab2d0199b0a298f77ccf3f0a019b457615e18e6dd8827f3573e0fe657d9ada3c36d6e8cd588e2b2c4a4090f
|
data/CHANGELOG.md
CHANGED
|
@@ -81,7 +81,7 @@ module Bullet
|
|
|
81
81
|
Thread.current.thread_variable_get(:bullet_eager_loadings)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
#
|
|
84
|
+
# call_stacks keeps stacktraces where querie-objects were called from.
|
|
85
85
|
# e.g. { 'Object:111' => [SomeProject/app/controllers/...] }
|
|
86
86
|
def call_stacks
|
|
87
87
|
Thread.current.thread_variable_get(:bullet_call_stacks)
|
|
@@ -27,7 +27,7 @@ module Bullet
|
|
|
27
27
|
)
|
|
28
28
|
if !excluded_stacktrace_path? && conditions_met?(object, associations)
|
|
29
29
|
Bullet.debug('detect n + 1 query', "object: #{object.bullet_key}, associations: #{associations}")
|
|
30
|
-
create_notification
|
|
30
|
+
create_notification(caller_in_project(object.bullet_key), object.class.to_s, associations)
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -38,16 +38,17 @@ module Bullet
|
|
|
38
38
|
objects = Array.wrap(object_or_objects)
|
|
39
39
|
class_names_match_regex = true
|
|
40
40
|
primary_key_values_are_empty = true
|
|
41
|
-
|
|
42
|
-
objects.
|
|
41
|
+
|
|
42
|
+
keys_joined = objects.map do |obj|
|
|
43
43
|
unless obj.class.name =~ /^HABTM_/
|
|
44
44
|
class_names_match_regex = false
|
|
45
45
|
end
|
|
46
46
|
unless obj.bullet_primary_key_value.nil?
|
|
47
47
|
primary_key_values_are_empty = false
|
|
48
48
|
end
|
|
49
|
-
|
|
50
|
-
end
|
|
49
|
+
obj.bullet_key
|
|
50
|
+
end.join(", ")
|
|
51
|
+
|
|
51
52
|
unless class_names_match_regex || primary_key_values_are_empty
|
|
52
53
|
Bullet.debug('Detector::NPlusOneQuery#add_possible_objects', "objects: #{keys_joined}")
|
|
53
54
|
objects.each { |object| possible_objects.add object.bullet_key }
|
data/lib/bullet/ext/object.rb
CHANGED
|
@@ -4,22 +4,20 @@ module Bullet
|
|
|
4
4
|
module Ext
|
|
5
5
|
module Object
|
|
6
6
|
refine ::Object do
|
|
7
|
+
attr_writer :bullet_key, :bullet_primary_key_value
|
|
8
|
+
|
|
7
9
|
def bullet_key
|
|
8
|
-
"#{self.class}:#{bullet_primary_key_value}"
|
|
10
|
+
@bullet_key ||= "#{self.class}:#{bullet_primary_key_value}"
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def bullet_primary_key_value
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if self.class.respond_to?(:primary_keys) && self.class.primary_keys
|
|
15
|
-
primary_key = self.class.primary_keys
|
|
16
|
-
elsif self.class.respond_to?(:primary_key) && self.class.primary_key
|
|
17
|
-
primary_key = self.class.primary_key
|
|
18
|
-
else
|
|
19
|
-
primary_key = :id
|
|
20
|
-
end
|
|
14
|
+
@bullet_primary_key_value ||= begin
|
|
15
|
+
return if respond_to?(:persisted?) && !persisted?
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
primary_key = self.class.try(:primary_keys) || self.class.try(:primary_key) || :id
|
|
18
|
+
|
|
19
|
+
bullet_join_potential_composite_primary_key(primary_key)
|
|
20
|
+
end
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
private
|
data/lib/bullet/ext/string.rb
CHANGED
|
@@ -7,7 +7,6 @@ using Bullet::Ext::Object
|
|
|
7
7
|
module Bullet
|
|
8
8
|
module StackTraceFilter
|
|
9
9
|
VENDOR_PATH = '/vendor'
|
|
10
|
-
IS_RUBY_19 = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
|
|
11
10
|
|
|
12
11
|
# @param bullet_key[String] - use this to get stored call stack from call_stacks object.
|
|
13
12
|
def caller_in_project(bullet_key = nil)
|
|
@@ -56,13 +55,12 @@ module Bullet
|
|
|
56
55
|
def location_as_path(location)
|
|
57
56
|
return location if location.is_a?(String)
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
location.absolute_path.to_s
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
def select_caller_locations(bullet_key = nil)
|
|
63
|
-
return caller.select { |caller_path| yield caller_path } if IS_RUBY_19
|
|
64
|
-
|
|
65
62
|
call_stack = bullet_key ? call_stacks[bullet_key] : caller_locations
|
|
63
|
+
|
|
66
64
|
call_stack.select { |location| yield location }
|
|
67
65
|
end
|
|
68
66
|
end
|
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.0.
|
|
4
|
+
version: 8.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Huang
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -98,7 +97,6 @@ licenses:
|
|
|
98
97
|
metadata:
|
|
99
98
|
changelog_uri: https://github.com/flyerhzm/bullet/blob/main/CHANGELOG.md
|
|
100
99
|
source_code_uri: https://github.com/flyerhzm/bullet
|
|
101
|
-
post_install_message:
|
|
102
100
|
rdoc_options: []
|
|
103
101
|
require_paths:
|
|
104
102
|
- lib
|
|
@@ -113,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
113
111
|
- !ruby/object:Gem::Version
|
|
114
112
|
version: 1.3.6
|
|
115
113
|
requirements: []
|
|
116
|
-
rubygems_version: 3.
|
|
117
|
-
signing_key:
|
|
114
|
+
rubygems_version: 3.6.2
|
|
118
115
|
specification_version: 4
|
|
119
116
|
summary: help to kill N+1 queries and unused eager loading.
|
|
120
117
|
test_files: []
|