bullet 4.4.0 → 4.5.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/CHANGELOG.md +31 -0
- data/{Hacking.textile → Hacking.md} +10 -5
- data/{README.textile → README.md} +174 -144
- data/lib/bullet.rb +42 -7
- data/lib/bullet/active_record2.rb +9 -9
- data/lib/bullet/active_record3.rb +9 -9
- data/lib/bullet/active_record3x.rb +8 -8
- data/lib/bullet/active_record4.rb +8 -8
- data/lib/bullet/detector.rb +2 -2
- data/lib/bullet/detector/association.rb +2 -43
- data/lib/bullet/detector/{counter.rb → counter_cache.rb} +13 -3
- data/lib/bullet/detector/n_plus_one_query.rb +21 -2
- data/lib/bullet/detector/{unused_eager_association.rb → unused_eager_loading.rb} +40 -3
- data/lib/bullet/mongoid2x.rb +5 -5
- data/lib/bullet/mongoid3x.rb +6 -6
- data/lib/bullet/version.rb +1 -1
- data/spec/bullet/detector/association_spec.rb +0 -49
- data/spec/bullet/detector/counter_cache_spec.rb +64 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +23 -1
- data/spec/bullet/detector/unused_eager_loading_spec.rb +95 -0
- data/spec/integration/association_spec.rb +141 -49
- data/spec/integration/{counter_spec.rb → counter_cache_spec.rb} +25 -1
- data/spec/integration/mongoid/association_spec.rb +24 -24
- data/spec/integration/rails2/association_spec.rb +49 -49
- data/spec/integration/rails2/{counter_spec.rb → counter_cache_spec.rb} +13 -1
- metadata +15 -14
- data/spec/bullet/detector/counter_spec.rb +0 -64
- data/spec/bullet/detector/unused_eager_association_spec.rb +0 -62
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
if active_record2?
|
4
|
-
describe Bullet::Detector::
|
4
|
+
describe Bullet::Detector::CounterCache do
|
5
5
|
before(:each) do
|
6
6
|
Bullet.start_request
|
7
7
|
end
|
@@ -35,5 +35,17 @@ if active_record2?
|
|
35
35
|
end
|
36
36
|
Bullet.collected_counter_cache_notifications.should be_empty
|
37
37
|
end
|
38
|
+
|
39
|
+
context "disable" do
|
40
|
+
before { Bullet.counter_cache_enable = false }
|
41
|
+
after { Bullet.counter_cache_enable = true }
|
42
|
+
|
43
|
+
it "should not detect counter cache" do
|
44
|
+
Country.all.each do |country|
|
45
|
+
country.cities.size
|
46
|
+
end
|
47
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
48
|
+
end
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
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.
|
4
|
+
version: 4.5.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: 2013-03-
|
11
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uniform_notifier
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- .rvmrc
|
37
37
|
- .rvmrc.example
|
38
38
|
- .travis.yml
|
39
|
+
- CHANGELOG.md
|
39
40
|
- Gemfile
|
40
41
|
- Gemfile.rails-2.3.17
|
41
42
|
- Gemfile.rails-3.0.20
|
@@ -43,9 +44,9 @@ files:
|
|
43
44
|
- Gemfile.rails-3.2.12
|
44
45
|
- Gemfile.rails-4-beta
|
45
46
|
- Guardfile
|
46
|
-
- Hacking.
|
47
|
+
- Hacking.md
|
47
48
|
- MIT-LICENSE
|
48
|
-
- README.
|
49
|
+
- README.md
|
49
50
|
- README_for_rails2.textile
|
50
51
|
- Rakefile
|
51
52
|
- bullet.gemspec
|
@@ -59,9 +60,9 @@ files:
|
|
59
60
|
- lib/bullet/detector.rb
|
60
61
|
- lib/bullet/detector/association.rb
|
61
62
|
- lib/bullet/detector/base.rb
|
62
|
-
- lib/bullet/detector/
|
63
|
+
- lib/bullet/detector/counter_cache.rb
|
63
64
|
- lib/bullet/detector/n_plus_one_query.rb
|
64
|
-
- lib/bullet/detector/
|
65
|
+
- lib/bullet/detector/unused_eager_loading.rb
|
65
66
|
- lib/bullet/ext/object.rb
|
66
67
|
- lib/bullet/ext/string.rb
|
67
68
|
- lib/bullet/mongoid2x.rb
|
@@ -82,9 +83,9 @@ files:
|
|
82
83
|
- rails/init.rb
|
83
84
|
- spec/bullet/detector/association_spec.rb
|
84
85
|
- spec/bullet/detector/base_spec.rb
|
85
|
-
- spec/bullet/detector/
|
86
|
+
- spec/bullet/detector/counter_cache_spec.rb
|
86
87
|
- spec/bullet/detector/n_plus_one_query_spec.rb
|
87
|
-
- spec/bullet/detector/
|
88
|
+
- spec/bullet/detector/unused_eager_loading_spec.rb
|
88
89
|
- spec/bullet/ext/object_spec.rb
|
89
90
|
- spec/bullet/ext/string_spec.rb
|
90
91
|
- spec/bullet/notification/base_spec.rb
|
@@ -97,10 +98,10 @@ files:
|
|
97
98
|
- spec/bullet/registry/base_spec.rb
|
98
99
|
- spec/bullet/registry/object_spec.rb
|
99
100
|
- spec/integration/association_spec.rb
|
100
|
-
- spec/integration/
|
101
|
+
- spec/integration/counter_cache_spec.rb
|
101
102
|
- spec/integration/mongoid/association_spec.rb
|
102
103
|
- spec/integration/rails2/association_spec.rb
|
103
|
-
- spec/integration/rails2/
|
104
|
+
- spec/integration/rails2/counter_cache_spec.rb
|
104
105
|
- spec/models/address.rb
|
105
106
|
- spec/models/author.rb
|
106
107
|
- spec/models/base_user.rb
|
@@ -165,9 +166,9 @@ summary: A rails plugin to kill N+1 queries and unused eager loading.
|
|
165
166
|
test_files:
|
166
167
|
- spec/bullet/detector/association_spec.rb
|
167
168
|
- spec/bullet/detector/base_spec.rb
|
168
|
-
- spec/bullet/detector/
|
169
|
+
- spec/bullet/detector/counter_cache_spec.rb
|
169
170
|
- spec/bullet/detector/n_plus_one_query_spec.rb
|
170
|
-
- spec/bullet/detector/
|
171
|
+
- spec/bullet/detector/unused_eager_loading_spec.rb
|
171
172
|
- spec/bullet/ext/object_spec.rb
|
172
173
|
- spec/bullet/ext/string_spec.rb
|
173
174
|
- spec/bullet/notification/base_spec.rb
|
@@ -180,10 +181,10 @@ test_files:
|
|
180
181
|
- spec/bullet/registry/base_spec.rb
|
181
182
|
- spec/bullet/registry/object_spec.rb
|
182
183
|
- spec/integration/association_spec.rb
|
183
|
-
- spec/integration/
|
184
|
+
- spec/integration/counter_cache_spec.rb
|
184
185
|
- spec/integration/mongoid/association_spec.rb
|
185
186
|
- spec/integration/rails2/association_spec.rb
|
186
|
-
- spec/integration/rails2/
|
187
|
+
- spec/integration/rails2/counter_cache_spec.rb
|
187
188
|
- spec/models/address.rb
|
188
189
|
- spec/models/author.rb
|
189
190
|
- spec/models/base_user.rb
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Bullet
|
4
|
-
module Detector
|
5
|
-
describe Counter do
|
6
|
-
before :all do
|
7
|
-
@post1 = Post.first
|
8
|
-
@post2 = Post.last
|
9
|
-
end
|
10
|
-
before(:each) { Counter.clear }
|
11
|
-
|
12
|
-
context ".clear" do
|
13
|
-
it "should clear all class variables" do
|
14
|
-
Counter.class_variable_get(:@@possible_objects).should be_nil
|
15
|
-
Counter.class_variable_get(:@@impossible_objects).should be_nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context ".add_counter_cache" do
|
20
|
-
it "should create notification if conditions met" do
|
21
|
-
Counter.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(true)
|
22
|
-
Counter.should_receive(:create_notification).with("Post", [:comments])
|
23
|
-
Counter.add_counter_cache(@post1, [:comments])
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not create notification if conditions not met" do
|
27
|
-
Counter.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(false)
|
28
|
-
Counter.should_receive(:create_notification).never
|
29
|
-
Counter.add_counter_cache(@post1, [:comments])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context ".add_possible_objects" do
|
34
|
-
it "should add possible objects" do
|
35
|
-
Counter.add_possible_objects([@post1, @post2])
|
36
|
-
Counter.send(:possible_objects).should be_include(@post1.bullet_ar_key)
|
37
|
-
Counter.send(:possible_objects).should be_include(@post2.bullet_ar_key)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should add impossible object" do
|
41
|
-
Counter.add_impossible_object(@post1)
|
42
|
-
Counter.send(:impossible_objects).should be_include(@post1.bullet_ar_key)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context ".conditions_met?" do
|
47
|
-
it "should be true when object is possible, not impossible" do
|
48
|
-
Counter.add_possible_objects(@post1)
|
49
|
-
Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_true
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should be false when object is not possible" do
|
53
|
-
Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should be true when object is possible, and impossible" do
|
57
|
-
Counter.add_possible_objects(@post1)
|
58
|
-
Counter.add_impossible_object(@post1)
|
59
|
-
Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Bullet
|
4
|
-
module Detector
|
5
|
-
describe UnusedEagerAssociation do
|
6
|
-
before(:all) { @post = Post.first }
|
7
|
-
before(:each) { UnusedEagerAssociation.clear }
|
8
|
-
|
9
|
-
context ".call_associations" do
|
10
|
-
it "should get empty array if eager_loadgins" do
|
11
|
-
UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should get call associations if object and association are both in eager_loadings and call_object_associations" do
|
15
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
16
|
-
UnusedEagerAssociation.add_call_object_associations(@post, :association)
|
17
|
-
UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should not get call associations if not exist in call_object_associations" do
|
21
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
22
|
-
UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context ".diff_object_associations" do
|
27
|
-
it "should return associations not exist in call_association" do
|
28
|
-
UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return empty if associations exist in call_association" do
|
32
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
33
|
-
UnusedEagerAssociation.add_call_object_associations(@post, :association)
|
34
|
-
UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context ".check_unused_preload_associations" do
|
39
|
-
it "should set @@checked to true" do
|
40
|
-
UnusedEagerAssociation.check_unused_preload_associations
|
41
|
-
UnusedEagerAssociation.class_variable_get(:@@checked).should be_true
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should create notification if object_association_diff is not empty" do
|
45
|
-
UnusedEagerAssociation.add_object_associations(@post, :association)
|
46
|
-
UnusedEagerAssociation.should_receive(:create_notification).with("Post", [:association])
|
47
|
-
UnusedEagerAssociation.check_unused_preload_associations
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should not create notification if object_association_diff is empty" do
|
51
|
-
UnusedEagerAssociation.clear
|
52
|
-
UnusedEagerAssociation.add_object_associations(@post, :association)
|
53
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
54
|
-
UnusedEagerAssociation.add_call_object_associations(@post, :association)
|
55
|
-
UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
56
|
-
UnusedEagerAssociation.should_not_receive(:create_notification).with("Post", [:association])
|
57
|
-
UnusedEagerAssociation.check_unused_preload_associations
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|