bullet 5.1.1 → 5.2.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/.travis.yml +13 -13
- data/CHANGELOG.md +2 -1
- data/Gemfile.mongoid-2.4 +0 -2
- data/Gemfile.mongoid-2.5 +0 -2
- data/Gemfile.mongoid-2.6 +0 -2
- data/Gemfile.mongoid-2.7 +0 -2
- data/Gemfile.mongoid-2.8 +0 -2
- data/Gemfile.mongoid-3.0 +0 -2
- data/Gemfile.mongoid-3.1 +0 -2
- data/Gemfile.mongoid-4.0 +0 -2
- data/Gemfile.mongoid-5.0 +0 -2
- data/Gemfile.rails-3.0 +0 -2
- data/Gemfile.rails-3.1 +0 -2
- data/Gemfile.rails-3.2 +0 -2
- data/Gemfile.rails-4.0 +0 -2
- data/Gemfile.rails-4.1 +0 -2
- data/Gemfile.rails-4.2 +0 -2
- data/Gemfile.rails-5.0 +1 -3
- data/README.md +1 -2
- data/lib/bullet/active_record5.rb +36 -45
- data/lib/bullet/version.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- 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: dbcef4cb1e9b0db722674cc600a456767eb5d2dd
|
4
|
+
data.tar.gz: 27107041da317defb0433329dc55375b305cc7b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea8208a3a4f1a1ef3f4f247667f9485b951a00ba5036cc87b8049005813e8f7452a5d340c1fdb09ea525fd5996b0050587a758afc8ff2a421f93acb21424f605
|
7
|
+
data.tar.gz: 456466364914301c30c4622bba947888bd16d92dad0603759c8b1108c4bc11ed417a8fca5a8ee2c983f119fa16e587cc140498393d2ec31f1a79c410082f1874
|
data/.travis.yml
CHANGED
@@ -5,7 +5,7 @@ rvm:
|
|
5
5
|
- 2.0
|
6
6
|
- 2.1
|
7
7
|
- 2.2
|
8
|
-
- 2.
|
8
|
+
- 2.3.0
|
9
9
|
gemfile:
|
10
10
|
- Gemfile.rails-5.0
|
11
11
|
- Gemfile.rails-4.2
|
@@ -63,14 +63,14 @@ matrix:
|
|
63
63
|
gemfile: Gemfile.rails-3.0
|
64
64
|
- rvm: 2.1
|
65
65
|
gemfile: Gemfile.rails-5.0
|
66
|
-
- rvm: 2.2
|
67
|
-
gemfile: Gemfile.rails-5.0
|
68
66
|
- rvm: 2.2
|
69
67
|
gemfile: Gemfile.rails-3.0
|
70
68
|
- rvm: 2.2
|
71
69
|
gemfile: Gemfile.rails-3.1
|
72
70
|
- rvm: 2.2
|
73
71
|
gemfile: Gemfile.rails-3.2
|
72
|
+
- rvm: 2.2
|
73
|
+
gemfile: Gemfile.rails-5.0
|
74
74
|
- rvm: 2.2
|
75
75
|
gemfile: Gemfile.mongoid-3.1
|
76
76
|
- rvm: 2.2
|
@@ -85,23 +85,23 @@ matrix:
|
|
85
85
|
gemfile: Gemfile.mongoid-2.5
|
86
86
|
- rvm: 2.2
|
87
87
|
gemfile: Gemfile.mongoid-2.4
|
88
|
-
- rvm: 2.
|
88
|
+
- rvm: 2.3.0
|
89
89
|
gemfile: Gemfile.rails-3.0
|
90
|
-
- rvm: 2.
|
90
|
+
- rvm: 2.3.0
|
91
91
|
gemfile: Gemfile.rails-3.1
|
92
|
-
- rvm: 2.
|
92
|
+
- rvm: 2.3.0
|
93
93
|
gemfile: Gemfile.rails-3.2
|
94
|
-
- rvm: 2.
|
94
|
+
- rvm: 2.3.0
|
95
95
|
gemfile: Gemfile.mongoid-3.1
|
96
|
-
- rvm: 2.
|
96
|
+
- rvm: 2.3.0
|
97
97
|
gemfile: Gemfile.mongoid-3.0
|
98
|
-
- rvm: 2.
|
98
|
+
- rvm: 2.3.0
|
99
99
|
gemfile: Gemfile.mongoid-2.8
|
100
|
-
- rvm: 2.
|
100
|
+
- rvm: 2.3.0
|
101
101
|
gemfile: Gemfile.mongoid-2.7
|
102
|
-
- rvm: 2.
|
102
|
+
- rvm: 2.3.0
|
103
103
|
gemfile: Gemfile.mongoid-2.6
|
104
|
-
- rvm: 2.
|
104
|
+
- rvm: 2.3.0
|
105
105
|
gemfile: Gemfile.mongoid-2.5
|
106
|
-
- rvm: 2.
|
106
|
+
- rvm: 2.3.0
|
107
107
|
gemfile: Gemfile.mongoid-2.4
|
data/CHANGELOG.md
CHANGED
data/Gemfile.mongoid-2.4
CHANGED
data/Gemfile.mongoid-2.5
CHANGED
data/Gemfile.mongoid-2.6
CHANGED
data/Gemfile.mongoid-2.7
CHANGED
data/Gemfile.mongoid-2.8
CHANGED
data/Gemfile.mongoid-3.0
CHANGED
data/Gemfile.mongoid-3.1
CHANGED
data/Gemfile.mongoid-4.0
CHANGED
data/Gemfile.mongoid-5.0
CHANGED
data/Gemfile.rails-3.0
CHANGED
data/Gemfile.rails-3.1
CHANGED
data/Gemfile.rails-3.2
CHANGED
data/Gemfile.rails-4.0
CHANGED
data/Gemfile.rails-4.1
CHANGED
data/Gemfile.rails-4.2
CHANGED
data/Gemfile.rails-5.0
CHANGED
@@ -2,15 +2,13 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '5.0.0
|
5
|
+
gem 'rails', '5.0.0'
|
6
6
|
gem 'sqlite3'
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'activerecord-import'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
11
|
|
12
|
-
gem 'coveralls', require: false
|
13
|
-
|
14
12
|
platforms :rbx do
|
15
13
|
gem 'rubysl', '~> 2.0'
|
16
14
|
gem 'rubinius-developer_tools'
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/bullet)
|
4
4
|
[](http://travis-ci.org/flyerhzm/bullet)
|
5
|
-
[](https://coveralls.io/r/flyerhzm/bullet)
|
6
5
|
<a href="https://codeclimate.com/github/flyerhzm/bullet"><img src="https://codeclimate.com/github/flyerhzm/bullet.png" /></a>
|
7
6
|
[](http://coderwall.com/flyerhzm)
|
8
7
|
|
@@ -63,7 +62,7 @@ config.after_initialize do
|
|
63
62
|
Bullet.add_footer = true
|
64
63
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
65
64
|
Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
|
66
|
-
Bullet.slack = { webhook_url: 'http://some.slack.url',
|
65
|
+
Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
|
67
66
|
end
|
68
67
|
```
|
69
68
|
|
@@ -40,38 +40,30 @@ module Bullet
|
|
40
40
|
::ActiveRecord::Base.prepend(SaveWithBulletSupport)
|
41
41
|
|
42
42
|
::ActiveRecord::Relation.class_eval do
|
43
|
-
alias_method :
|
43
|
+
alias_method :origin_records, :records
|
44
44
|
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
45
45
|
# if select only one object, then the only one object has impossible to cause N+1 query.
|
46
|
-
def
|
47
|
-
|
46
|
+
def records
|
47
|
+
result = origin_records
|
48
48
|
if Bullet.start?
|
49
|
-
if
|
50
|
-
if
|
51
|
-
Bullet::Detector::NPlusOneQuery.add_possible_objects(
|
52
|
-
Bullet::Detector::CounterCache.add_possible_objects(
|
53
|
-
elsif
|
54
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(
|
55
|
-
Bullet::Detector::CounterCache.add_impossible_object(
|
49
|
+
if result.first.class.name !~ /^HABTM_/
|
50
|
+
if result.size > 1
|
51
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
52
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
53
|
+
elsif result.size == 1
|
54
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result.first)
|
55
|
+
Bullet::Detector::CounterCache.add_impossible_object(result.first)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
::ActiveRecord::Associations::Association.class_eval do
|
64
|
-
alias_method :origin_initialize, :initialize
|
65
|
-
def initialize(owner, reflection)
|
66
|
-
origin_initialize(owner, reflection)
|
67
|
-
reflection.set_owner owner
|
59
|
+
result
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
71
63
|
::ActiveRecord::Associations::Preloader.class_eval do
|
72
|
-
alias_method :
|
64
|
+
alias_method :origin_preloaders_for_one, :preloaders_for_one
|
73
65
|
|
74
|
-
def
|
66
|
+
def preloaders_for_one(association, records, scope)
|
75
67
|
if Bullet.start?
|
76
68
|
records.compact!
|
77
69
|
if records.first.class.name !~ /^HABTM_/
|
@@ -81,7 +73,7 @@ module Bullet
|
|
81
73
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
|
82
74
|
end
|
83
75
|
end
|
84
|
-
|
76
|
+
origin_preloaders_for_one(association, records, scope)
|
85
77
|
end
|
86
78
|
end
|
87
79
|
|
@@ -144,7 +136,14 @@ module Bullet
|
|
144
136
|
|
145
137
|
if Bullet.start?
|
146
138
|
if records.size > 1
|
147
|
-
|
139
|
+
if self.is_a? ::ActiveRecord::Associations::ThroughAssociation
|
140
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
|
141
|
+
association = self.owner.association self.through_reflection.name
|
142
|
+
association.target.each do |through_record|
|
143
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
|
148
147
|
end
|
149
148
|
if records.first.class.name !~ /^HABTM_/
|
150
149
|
if records.size > 1
|
@@ -161,8 +160,8 @@ module Bullet
|
|
161
160
|
|
162
161
|
alias_method :origin_empty?, :empty?
|
163
162
|
def empty?
|
164
|
-
if Bullet.start? &&
|
165
|
-
Bullet::Detector::NPlusOneQuery.call_association(
|
163
|
+
if Bullet.start? && !reflection.has_cached_counter?
|
164
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
166
165
|
end
|
167
166
|
origin_empty?
|
168
167
|
end
|
@@ -170,7 +169,7 @@ module Bullet
|
|
170
169
|
alias_method :origin_include?, :include?
|
171
170
|
def include?(object)
|
172
171
|
if Bullet.start?
|
173
|
-
Bullet::Detector::NPlusOneQuery.call_association(
|
172
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
174
173
|
end
|
175
174
|
origin_include?(object)
|
176
175
|
end
|
@@ -182,9 +181,9 @@ module Bullet
|
|
182
181
|
def reader(force_reload = false)
|
183
182
|
result = origin_reader(force_reload)
|
184
183
|
if Bullet.start?
|
185
|
-
if
|
186
|
-
Bullet::Detector::NPlusOneQuery.call_association(
|
187
|
-
if Bullet::Detector::NPlusOneQuery.impossible?(
|
184
|
+
if owner.class.name !~ /^HABTM_/ && !@inversed
|
185
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
186
|
+
if Bullet::Detector::NPlusOneQuery.impossible?(owner)
|
188
187
|
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
189
188
|
else
|
190
189
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(result) if result
|
@@ -198,28 +197,20 @@ module Bullet
|
|
198
197
|
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
199
198
|
alias_method :origin_many_empty?, :empty?
|
200
199
|
def empty?
|
201
|
-
Thread.current[:bullet_collection_empty] = true
|
202
200
|
result = origin_many_empty?
|
203
|
-
|
204
|
-
|
205
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
201
|
+
if Bullet.start? && !reflection.has_cached_counter?
|
202
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
|
206
203
|
end
|
207
204
|
result
|
208
205
|
end
|
209
|
-
end
|
210
|
-
|
211
|
-
::ActiveRecord::Reflection::AbstractReflection.class_eval do
|
212
|
-
def set_owner(owner)
|
213
|
-
@owner = owner
|
214
|
-
end
|
215
206
|
|
216
|
-
alias_method :
|
217
|
-
def
|
218
|
-
result =
|
219
|
-
if Bullet.start? && !result && !
|
220
|
-
Bullet::Detector::CounterCache.add_counter_cache(
|
207
|
+
alias_method :origin_count_records, :count_records
|
208
|
+
def count_records
|
209
|
+
result = reflection.has_cached_counter?
|
210
|
+
if Bullet.start? && !result && !self.is_a?(::ActiveRecord::Associations::ThroughAssociation)
|
211
|
+
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
|
221
212
|
end
|
222
|
-
|
213
|
+
origin_count_records
|
223
214
|
end
|
224
215
|
end
|
225
216
|
end
|
data/lib/bullet/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -30,9 +30,6 @@ $LOAD_PATH.unshift(MODELS)
|
|
30
30
|
SUPPORT = File.join(File.dirname(__FILE__), "support")
|
31
31
|
Dir[ File.join(SUPPORT, "*.rb") ].reject { |filename| filename =~ /_seed.rb$/ }.sort.each { |file| require file }
|
32
32
|
|
33
|
-
require 'coveralls'
|
34
|
-
Coveralls.wear!
|
35
|
-
|
36
33
|
RSpec.configure do |config|
|
37
34
|
config.extend Bullet::Dependency
|
38
35
|
|
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.
|
4
|
+
version: 5.2.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-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|