bullet 4.14.0 → 5.0.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 +56 -1
- data/CHANGELOG.md +53 -0
- data/Gemfile.mongoid +0 -2
- data/Gemfile.mongoid-2.4 +2 -4
- data/Gemfile.mongoid-2.5 +2 -4
- data/Gemfile.mongoid-2.6 +1 -3
- data/Gemfile.mongoid-2.7 +2 -4
- data/Gemfile.mongoid-2.8 +2 -4
- data/Gemfile.mongoid-3.0 +2 -4
- data/Gemfile.mongoid-3.1 +2 -4
- data/Gemfile.mongoid-4.0 +1 -3
- data/Gemfile.mongoid-5.0 +17 -0
- data/Gemfile.rails-3.0 +1 -3
- data/Gemfile.rails-3.1 +1 -3
- data/Gemfile.rails-3.2 +1 -3
- data/Gemfile.rails-4.0 +1 -3
- data/Gemfile.rails-4.1 +1 -3
- data/Gemfile.rails-4.2 +1 -3
- data/Gemfile.rails-5.0 +17 -0
- data/README.md +31 -2
- data/bullet.gemspec +1 -1
- data/lib/bullet/active_record3.rb +65 -35
- data/lib/bullet/active_record3x.rb +54 -32
- data/lib/bullet/active_record4.rb +62 -30
- data/lib/bullet/active_record41.rb +63 -32
- data/lib/bullet/active_record42.rb +105 -40
- data/lib/bullet/active_record5.rb +217 -0
- data/lib/bullet/dependency.rb +16 -0
- data/lib/bullet/detector/association.rb +16 -16
- data/lib/bullet/detector/counter_cache.rb +13 -13
- data/lib/bullet/detector/n_plus_one_query.rb +33 -24
- data/lib/bullet/detector/unused_eager_loading.rb +1 -1
- data/lib/bullet/ext/object.rb +3 -1
- data/lib/bullet/mongoid5x.rb +56 -0
- data/lib/bullet/notification/base.rb +1 -1
- data/lib/bullet/notification/n_plus_one_query.rb +6 -0
- data/lib/bullet/rack.rb +19 -11
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +28 -11
- data/spec/bullet/detector/counter_cache_spec.rb +8 -8
- data/spec/bullet/detector/n_plus_one_query_spec.rb +42 -27
- data/spec/bullet/ext/object_spec.rb +6 -0
- data/spec/bullet/notification/base_spec.rb +2 -2
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +1 -1
- data/spec/bullet/rack_spec.rb +3 -3
- data/spec/bullet_spec.rb +47 -0
- data/spec/integration/active_record3/association_spec.rb +11 -2
- data/spec/integration/active_record4/association_spec.rb +58 -3
- data/spec/integration/active_record5/association_spec.rb +715 -0
- data/spec/integration/counter_cache_spec.rb +17 -1
- data/spec/models/category.rb +4 -1
- data/spec/models/comment.rb +2 -0
- data/spec/models/post.rb +7 -2
- data/spec/models/reply.rb +3 -0
- data/spec/models/submission.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/mongo_seed.rb +13 -0
- data/spec/support/sqlite_seed.rb +14 -6
- data/test.sh +1 -0
- data/update.sh +15 -0
- metadata +16 -7
|
@@ -29,6 +29,22 @@ if !mongoid? && active_record?
|
|
|
29
29
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
if active_record5?
|
|
33
|
+
it "should not need counter cache for has_many through" do
|
|
34
|
+
Client.all.each do |client|
|
|
35
|
+
client.firms.size
|
|
36
|
+
end
|
|
37
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
38
|
+
end
|
|
39
|
+
else
|
|
40
|
+
it "should need counter cache for has_many through" do
|
|
41
|
+
Client.all.each do |client|
|
|
42
|
+
client.firms.size
|
|
43
|
+
end
|
|
44
|
+
expect(Bullet.collected_counter_cache_notifications).not_to be_empty
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
32
48
|
it "should not need counter cache with part of cities" do
|
|
33
49
|
Country.all.each do |country|
|
|
34
50
|
country.cities.where(:name => 'first').size
|
|
@@ -50,7 +66,7 @@ if !mongoid? && active_record?
|
|
|
50
66
|
|
|
51
67
|
context "whitelist" do
|
|
52
68
|
before { Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities }
|
|
53
|
-
after { Bullet.
|
|
69
|
+
after { Bullet.clear_whitelist }
|
|
54
70
|
|
|
55
71
|
it "should not detect counter cache" do
|
|
56
72
|
Country.all.each do |country|
|
data/spec/models/category.rb
CHANGED
data/spec/models/comment.rb
CHANGED
data/spec/models/post.rb
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
class Post < ActiveRecord::Base
|
|
2
|
-
extend Bullet::Dependency
|
|
3
|
-
|
|
4
2
|
belongs_to :category, inverse_of: :posts
|
|
5
3
|
belongs_to :writer
|
|
6
4
|
has_many :comments, inverse_of: :post
|
|
7
5
|
|
|
6
|
+
validates :category, presence: true
|
|
7
|
+
|
|
8
8
|
scope :preload_comments, -> { includes(:comments) }
|
|
9
9
|
scope :in_category_name, ->(name) { where(['categories.name = ?', name]).includes(:category) }
|
|
10
|
+
scope :draft, -> { where(active: false) }
|
|
11
|
+
|
|
12
|
+
def link=(*)
|
|
13
|
+
comments.new
|
|
14
|
+
end
|
|
10
15
|
end
|
data/spec/models/submission.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -56,11 +56,12 @@ if active_record?
|
|
|
56
56
|
Support::SqliteSeed.seed_db
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
config.before(:
|
|
59
|
+
config.before(:example) do
|
|
60
60
|
Bullet.start_request
|
|
61
|
+
Bullet.enable = true
|
|
61
62
|
end
|
|
62
63
|
|
|
63
|
-
config.after(:
|
|
64
|
+
config.after(:example) do
|
|
64
65
|
Bullet.end_request
|
|
65
66
|
end
|
|
66
67
|
end
|
data/spec/support/mongo_seed.rb
CHANGED
|
@@ -52,6 +52,19 @@ module Support
|
|
|
52
52
|
}
|
|
53
53
|
)
|
|
54
54
|
end
|
|
55
|
+
elsif Mongoid::VERSION =~ /\A5/
|
|
56
|
+
Mongoid.configure do |config|
|
|
57
|
+
config.load_configuration(
|
|
58
|
+
clients: {
|
|
59
|
+
default: {
|
|
60
|
+
database: "bullet",
|
|
61
|
+
hosts: [ "localhost:27017" ]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
# Increase the level from DEBUG in order to avoid excessive logging to the screen
|
|
67
|
+
Mongo::Logger.logger.level = Logger::WARN
|
|
55
68
|
end
|
|
56
69
|
end
|
|
57
70
|
|
data/spec/support/sqlite_seed.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Support
|
|
|
14
14
|
category2 = Category.create(:name => 'second')
|
|
15
15
|
|
|
16
16
|
post1 = category1.posts.create(:name => 'first', :writer => writer1)
|
|
17
|
-
post1a = category1.posts.create(:name => 'like first', :writer => writer2)
|
|
17
|
+
post1a = category1.posts.create(:name => 'like first', :writer => writer2, active: false)
|
|
18
18
|
post2 = category2.posts.create(:name => 'second', :writer => writer2)
|
|
19
19
|
|
|
20
20
|
comment1 = post1.comments.create(:name => 'first', :author => writer1)
|
|
@@ -82,10 +82,13 @@ module Support
|
|
|
82
82
|
user1 = User.create(:name => 'user1', :category => category1)
|
|
83
83
|
user2 = User.create(:name => 'user2', :category => category1)
|
|
84
84
|
|
|
85
|
-
submission1 =
|
|
86
|
-
submission2 =
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
submission1 = user1.create_submission(:name => "submission1")
|
|
86
|
+
submission2 = user2.create_submission(:name => "submission2")
|
|
87
|
+
|
|
88
|
+
submission1.replies.create(:name => 'reply1')
|
|
89
|
+
submission1.replies.create(:name => 'reply2')
|
|
90
|
+
submission2.replies.create(:name => 'reply3')
|
|
91
|
+
submission2.replies.create(:name => 'reply4')
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
def setup_db
|
|
@@ -191,6 +194,7 @@ module Support
|
|
|
191
194
|
t.column :name, :string
|
|
192
195
|
t.column :category_id, :integer
|
|
193
196
|
t.column :writer_id, :integer
|
|
197
|
+
t.column :active, :boolean, :default => true
|
|
194
198
|
end
|
|
195
199
|
|
|
196
200
|
create_table :relationships do |t|
|
|
@@ -211,9 +215,13 @@ module Support
|
|
|
211
215
|
t.column :name, :string
|
|
212
216
|
end
|
|
213
217
|
|
|
218
|
+
create_table :replies do |t|
|
|
219
|
+
t.column :name, :string
|
|
220
|
+
t.column :submission_id, :integer
|
|
221
|
+
end
|
|
222
|
+
|
|
214
223
|
create_table :submissions do |t|
|
|
215
224
|
t.column :name, :string
|
|
216
|
-
t.column :category_id, :integer
|
|
217
225
|
t.column :user_id, :integer
|
|
218
226
|
end
|
|
219
227
|
|
data/test.sh
CHANGED
|
@@ -6,6 +6,7 @@ BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.0 bund
|
|
|
6
6
|
BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle exec rspec spec
|
|
7
7
|
BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle exec rspec spec
|
|
8
8
|
BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle exec rspec spec
|
|
9
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle exec rspec spec
|
|
9
10
|
BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle exec rspec spec
|
|
10
11
|
BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle exec rspec spec
|
|
11
12
|
BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle exec rspec spec
|
data/update.sh
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle update
|
|
2
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle update
|
|
3
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle update
|
|
4
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle update
|
|
5
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle update
|
|
6
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle update
|
|
7
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle update
|
|
8
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle update
|
|
9
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle update
|
|
10
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle update
|
|
11
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.8 bundle update
|
|
12
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.7 bundle update
|
|
13
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.6 bundle update
|
|
14
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.5 bundle update
|
|
15
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.4 bundle update
|
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:
|
|
4
|
+
version: 5.0.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:
|
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -28,16 +28,16 @@ dependencies:
|
|
|
28
28
|
name: uniform_notifier
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.
|
|
33
|
+
version: 1.9.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 1.
|
|
40
|
+
version: 1.9.0
|
|
41
41
|
description: help to kill N+1 queries and unused eager loading.
|
|
42
42
|
email:
|
|
43
43
|
- flyerhzm@gmail.com
|
|
@@ -59,12 +59,14 @@ files:
|
|
|
59
59
|
- Gemfile.mongoid-3.0
|
|
60
60
|
- Gemfile.mongoid-3.1
|
|
61
61
|
- Gemfile.mongoid-4.0
|
|
62
|
+
- Gemfile.mongoid-5.0
|
|
62
63
|
- Gemfile.rails-3.0
|
|
63
64
|
- Gemfile.rails-3.1
|
|
64
65
|
- Gemfile.rails-3.2
|
|
65
66
|
- Gemfile.rails-4.0
|
|
66
67
|
- Gemfile.rails-4.1
|
|
67
68
|
- Gemfile.rails-4.2
|
|
69
|
+
- Gemfile.rails-5.0
|
|
68
70
|
- Guardfile
|
|
69
71
|
- Hacking.md
|
|
70
72
|
- MIT-LICENSE
|
|
@@ -77,6 +79,7 @@ files:
|
|
|
77
79
|
- lib/bullet/active_record4.rb
|
|
78
80
|
- lib/bullet/active_record41.rb
|
|
79
81
|
- lib/bullet/active_record42.rb
|
|
82
|
+
- lib/bullet/active_record5.rb
|
|
80
83
|
- lib/bullet/dependency.rb
|
|
81
84
|
- lib/bullet/detector.rb
|
|
82
85
|
- lib/bullet/detector/association.rb
|
|
@@ -89,6 +92,7 @@ files:
|
|
|
89
92
|
- lib/bullet/mongoid2x.rb
|
|
90
93
|
- lib/bullet/mongoid3x.rb
|
|
91
94
|
- lib/bullet/mongoid4x.rb
|
|
95
|
+
- lib/bullet/mongoid5x.rb
|
|
92
96
|
- lib/bullet/notification.rb
|
|
93
97
|
- lib/bullet/notification/base.rb
|
|
94
98
|
- lib/bullet/notification/counter_cache.rb
|
|
@@ -122,6 +126,7 @@ files:
|
|
|
122
126
|
- spec/bullet_spec.rb
|
|
123
127
|
- spec/integration/active_record3/association_spec.rb
|
|
124
128
|
- spec/integration/active_record4/association_spec.rb
|
|
129
|
+
- spec/integration/active_record5/association_spec.rb
|
|
125
130
|
- spec/integration/counter_cache_spec.rb
|
|
126
131
|
- spec/integration/mongoid/association_spec.rb
|
|
127
132
|
- spec/models/address.rb
|
|
@@ -150,6 +155,7 @@ files:
|
|
|
150
155
|
- spec/models/pet.rb
|
|
151
156
|
- spec/models/post.rb
|
|
152
157
|
- spec/models/relationship.rb
|
|
158
|
+
- spec/models/reply.rb
|
|
153
159
|
- spec/models/student.rb
|
|
154
160
|
- spec/models/submission.rb
|
|
155
161
|
- spec/models/teacher.rb
|
|
@@ -162,6 +168,7 @@ files:
|
|
|
162
168
|
- spec/support/sqlite_seed.rb
|
|
163
169
|
- tasks/bullet_tasks.rake
|
|
164
170
|
- test.sh
|
|
171
|
+
- update.sh
|
|
165
172
|
homepage: http://github.com/flyerhzm/bullet
|
|
166
173
|
licenses:
|
|
167
174
|
- MIT
|
|
@@ -182,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
182
189
|
version: 1.3.6
|
|
183
190
|
requirements: []
|
|
184
191
|
rubyforge_project:
|
|
185
|
-
rubygems_version: 2.
|
|
192
|
+
rubygems_version: 2.5.1
|
|
186
193
|
signing_key:
|
|
187
194
|
specification_version: 4
|
|
188
195
|
summary: help to kill N+1 queries and unused eager loading.
|
|
@@ -206,6 +213,7 @@ test_files:
|
|
|
206
213
|
- spec/bullet_spec.rb
|
|
207
214
|
- spec/integration/active_record3/association_spec.rb
|
|
208
215
|
- spec/integration/active_record4/association_spec.rb
|
|
216
|
+
- spec/integration/active_record5/association_spec.rb
|
|
209
217
|
- spec/integration/counter_cache_spec.rb
|
|
210
218
|
- spec/integration/mongoid/association_spec.rb
|
|
211
219
|
- spec/models/address.rb
|
|
@@ -234,6 +242,7 @@ test_files:
|
|
|
234
242
|
- spec/models/pet.rb
|
|
235
243
|
- spec/models/post.rb
|
|
236
244
|
- spec/models/relationship.rb
|
|
245
|
+
- spec/models/reply.rb
|
|
237
246
|
- spec/models/student.rb
|
|
238
247
|
- spec/models/submission.rb
|
|
239
248
|
- spec/models/teacher.rb
|