bullet 8.0.1 → 8.0.2
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 +4 -0
- data/README.md +25 -5
- data/lib/bullet/dependency.rb +6 -0
- data/lib/bullet/ext/object.rb +8 -5
- data/lib/bullet/mongoid9x.rb +72 -0
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ace15062b915463985d5257ca7b054b482ca842f05f832dc45c1134bc7c8cd
|
4
|
+
data.tar.gz: a43533c8d894791edffcb4cbd9ad4ceba1dd238a8b736d23e3444ca7f766c57c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 262e12b9be4eeae23494a06eb71d6c6823674ecfa8ec9a0c5a5eaff7d7bf268a52cb35ee8198cf0712312745735bc4ad2a6474e3a6a5a6fa8820ed896754795a
|
7
|
+
data.tar.gz: b16503b483682cb94121442f8ee1d74145cb835031e62a864765629b0dbffd6b360136ee3b09f1b14d1e35a25794c06ace1579415829ad0dfdcff1ae2be0b3bf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -121,8 +121,6 @@ Bullet.unused_eager_loading_enable = false
|
|
121
121
|
Bullet.counter_cache_enable = false
|
122
122
|
```
|
123
123
|
|
124
|
-
Note: When calling `Bullet.enable`, all other detectors are reset to their defaults (`true`) and need reconfiguring.
|
125
|
-
|
126
124
|
## Safe list
|
127
125
|
|
128
126
|
Sometimes Bullet may notify you of query problems you don't care to fix, or
|
@@ -240,7 +238,7 @@ If your application generates a Content-Security-Policy via a separate middlewar
|
|
240
238
|
|
241
239
|
### Run in tests
|
242
240
|
|
243
|
-
First you need to enable Bullet in test environment.
|
241
|
+
First you need to enable Bullet in the test environment.
|
244
242
|
|
245
243
|
```ruby
|
246
244
|
# config/environments/test.rb
|
@@ -251,11 +249,13 @@ config.after_initialize do
|
|
251
249
|
end
|
252
250
|
```
|
253
251
|
|
254
|
-
Then wrap each test in Bullet api.
|
252
|
+
Then wrap each test in the Bullet api.
|
253
|
+
|
254
|
+
With RSpec:
|
255
255
|
|
256
256
|
```ruby
|
257
257
|
# spec/rails_helper.rb
|
258
|
-
|
258
|
+
RSpec.configure do |config|
|
259
259
|
config.before(:each) do
|
260
260
|
Bullet.start_request
|
261
261
|
end
|
@@ -267,6 +267,26 @@ if Bullet.enable?
|
|
267
267
|
end
|
268
268
|
```
|
269
269
|
|
270
|
+
With Minitest:
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
# test/test_helper.rb
|
274
|
+
module ActiveSupport
|
275
|
+
class TestCase
|
276
|
+
def before_setup
|
277
|
+
Bullet.start_request
|
278
|
+
super
|
279
|
+
end
|
280
|
+
|
281
|
+
def after_teardown
|
282
|
+
super
|
283
|
+
Bullet.perform_out_of_channel_notifications if Bullet.notification?
|
284
|
+
Bullet.end_request
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
```
|
289
|
+
|
270
290
|
## Debug Mode
|
271
291
|
|
272
292
|
Bullet outputs some details info, to enable debug mode, set
|
data/lib/bullet/dependency.rb
CHANGED
@@ -56,6 +56,8 @@ module Bullet
|
|
56
56
|
'mongoid7x'
|
57
57
|
elsif mongoid8x?
|
58
58
|
'mongoid8x'
|
59
|
+
elsif mongoid9x?
|
60
|
+
'mongoid9x'
|
59
61
|
else
|
60
62
|
raise "Bullet does not support mongoid #{::Mongoid::VERSION} yet"
|
61
63
|
end
|
@@ -149,5 +151,9 @@ module Bullet
|
|
149
151
|
def mongoid8x?
|
150
152
|
mongoid? && ::Mongoid::VERSION =~ /\A8/
|
151
153
|
end
|
154
|
+
|
155
|
+
def mongoid9x?
|
156
|
+
mongoid? && ::Mongoid::VERSION =~ /\A9/
|
157
|
+
end
|
152
158
|
end
|
153
159
|
end
|
data/lib/bullet/ext/object.rb
CHANGED
@@ -7,17 +7,20 @@ module Bullet
|
|
7
7
|
attr_writer :bullet_key, :bullet_primary_key_value
|
8
8
|
|
9
9
|
def bullet_key
|
10
|
+
return "#{self.class}:" if respond_to?(:persisted?) && !persisted?
|
11
|
+
|
10
12
|
@bullet_key ||= "#{self.class}:#{bullet_primary_key_value}"
|
11
13
|
end
|
12
14
|
|
13
15
|
def bullet_primary_key_value
|
14
|
-
|
15
|
-
return if respond_to?(:persisted?) && !persisted?
|
16
|
+
return if respond_to?(:persisted?) && !persisted?
|
16
17
|
|
17
|
-
|
18
|
+
@bullet_primary_key_value ||=
|
19
|
+
begin
|
20
|
+
primary_key = self.class.try(:primary_keys) || self.class.try(:primary_key) || :id
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
bullet_join_potential_composite_primary_key(primary_key)
|
23
|
+
end
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bullet
|
4
|
+
module Mongoid
|
5
|
+
def self.enable
|
6
|
+
require 'mongoid'
|
7
|
+
require 'rubygems'
|
8
|
+
::Mongoid::Contextual::Mongo.class_eval do
|
9
|
+
alias_method :origin_first, :first
|
10
|
+
alias_method :origin_last, :last
|
11
|
+
alias_method :origin_each, :each
|
12
|
+
alias_method :origin_eager_load, :eager_load
|
13
|
+
|
14
|
+
%i[first last].each do |context|
|
15
|
+
default = Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new('7.5') ? nil : {}
|
16
|
+
define_method(context) do |opts = default|
|
17
|
+
result = send(:"origin_#{context}", opts)
|
18
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def each(&_block)
|
24
|
+
return to_enum unless block_given?
|
25
|
+
|
26
|
+
first_document = nil
|
27
|
+
document_count = 0
|
28
|
+
|
29
|
+
origin_each do |document|
|
30
|
+
document_count += 1
|
31
|
+
|
32
|
+
if document_count == 1
|
33
|
+
first_document = document
|
34
|
+
elsif document_count == 2
|
35
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects([first_document, document])
|
36
|
+
yield(first_document)
|
37
|
+
first_document = nil
|
38
|
+
yield(document)
|
39
|
+
else
|
40
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(document)
|
41
|
+
yield(document)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if document_count == 1
|
46
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(first_document)
|
47
|
+
yield(first_document)
|
48
|
+
end
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def eager_load(docs)
|
54
|
+
associations = criteria.inclusions.map(&:name)
|
55
|
+
docs.each { |doc| Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations) }
|
56
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
|
57
|
+
origin_eager_load(docs)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
::Mongoid::Association::Accessors.class_eval do
|
62
|
+
alias_method :origin_get_relation, :get_relation
|
63
|
+
|
64
|
+
def get_relation(name, association, object, reload = false)
|
65
|
+
result = origin_get_relation(name, association, object, reload)
|
66
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name) unless association.embedded?
|
67
|
+
result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
@@ -64,7 +64,7 @@ module Bullet
|
|
64
64
|
].freeze
|
65
65
|
|
66
66
|
def enable=(enable)
|
67
|
-
@enable =
|
67
|
+
@enable = enable
|
68
68
|
|
69
69
|
if enable?
|
70
70
|
reset_safelist
|
@@ -90,15 +90,15 @@ module Bullet
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def n_plus_one_query_enable?
|
93
|
-
enable? &&
|
93
|
+
enable? && (@n_plus_one_query_enable.nil? ? true : @n_plus_one_query_enable)
|
94
94
|
end
|
95
95
|
|
96
96
|
def unused_eager_loading_enable?
|
97
|
-
enable? &&
|
97
|
+
enable? && (@unused_eager_loading_enable.nil? ? true : @unused_eager_loading_enable)
|
98
98
|
end
|
99
99
|
|
100
100
|
def counter_cache_enable?
|
101
|
-
enable? &&
|
101
|
+
enable? && (@counter_cache_enable.nil? ? true : @counter_cache_enable)
|
102
102
|
end
|
103
103
|
|
104
104
|
def stacktrace_includes
|
metadata
CHANGED
@@ -1,13 +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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02
|
10
|
+
date: 2025-04-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/bullet/mongoid6x.rb
|
76
76
|
- lib/bullet/mongoid7x.rb
|
77
77
|
- lib/bullet/mongoid8x.rb
|
78
|
+
- lib/bullet/mongoid9x.rb
|
78
79
|
- lib/bullet/notification.rb
|
79
80
|
- lib/bullet/notification/base.rb
|
80
81
|
- lib/bullet/notification/counter_cache.rb
|