bullet 4.3.0 → 4.4.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 +7 -0
- data/.travis.yml +4 -4
- data/Gemfile +3 -5
- data/{Gemfile.rails-2.3.14 → Gemfile.rails-2.3.17} +2 -4
- data/{Gemfile.rails-3.0.17 → Gemfile.rails-3.0.20} +2 -4
- data/{Gemfile.rails-3.1.8 → Gemfile.rails-3.1.11} +2 -4
- data/{Gemfile.rails-3.2.9 → Gemfile.rails-3.2.12} +2 -4
- data/Gemfile.rails-4-beta +2 -6
- data/README.textile +6 -10
- data/README_for_rails2.textile +6 -10
- data/lib/bullet/active_record3x.rb +3 -3
- data/lib/bullet/active_record4.rb +94 -0
- data/lib/bullet/dependency.rb +3 -1
- data/lib/bullet/rack.rb +3 -8
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +1 -1
- data/perf/benchmark.rb +1 -4
- data/spec/bullet/rack_spec.rb +0 -10
- data/spec/integration/association_spec.rb +14 -14
- data/spec/integration/counter_spec.rb +1 -1
- data/test.sh +4 -4
- metadata +14 -20
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1ecb17e9a4a015f9ff8895fc39a7ed2bd3a5e600
|
|
4
|
+
data.tar.gz: a624e5f8bc8d40f8bf49eab595725ce2de0076c4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e05204d7d248ac6888897a4235b716c4c74dbf793083f1aec5a693d88d1250ab6c12854967e93096c667e7a73b9bf54cc10799fd8428c7a67d7bc1672db288a4
|
|
7
|
+
data.tar.gz: 4bfdcde512f2583b6285663722c526972d7263aaeffc62173f651feaca77384c9a98678518286789fe79b3923393e7bf8e76bb33b7438df4c4033ff0c08206a8
|
data/.travis.yml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
rvm:
|
|
3
|
-
-
|
|
3
|
+
- 2.0.0
|
|
4
4
|
gemfile:
|
|
5
5
|
- Gemfile
|
|
6
6
|
- Gemfile.rails-4-beta
|
|
7
|
-
- Gemfile.rails-3.
|
|
8
|
-
- Gemfile.rails-3.
|
|
9
|
-
- Gemfile.rails-
|
|
7
|
+
- Gemfile.rails-3.2.12
|
|
8
|
+
- Gemfile.rails-3.1.11
|
|
9
|
+
- Gemfile.rails-3.0.20
|
|
10
10
|
env: DB=sqlite
|
|
11
11
|
services: mongodb
|
|
12
12
|
before_install:
|
data/Gemfile
CHANGED
|
@@ -4,14 +4,12 @@ source "http://rubygems.org"
|
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem 'rails', '3.2.
|
|
7
|
+
gem 'rails', '3.2.11'
|
|
8
8
|
gem 'sqlite3'
|
|
9
|
-
gem '
|
|
9
|
+
gem 'mysql2'
|
|
10
10
|
gem 'activerecord-import'
|
|
11
|
-
gem 'mongoid', '3.0.
|
|
11
|
+
gem 'mongoid', '3.0.9'
|
|
12
12
|
|
|
13
13
|
gem "rspec"
|
|
14
14
|
gem "guard"
|
|
15
15
|
gem "guard-rspec"
|
|
16
|
-
|
|
17
|
-
gem "perftools.rb"
|
|
@@ -4,14 +4,12 @@ source "http://rubygems.org"
|
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem 'rails', '3.0.
|
|
7
|
+
gem 'rails', '3.0.20'
|
|
8
8
|
gem 'sqlite3'
|
|
9
|
-
gem '
|
|
9
|
+
gem 'mysql2'
|
|
10
10
|
gem 'activerecord-import'
|
|
11
11
|
gem 'bson_ext'
|
|
12
12
|
|
|
13
13
|
gem "rspec"
|
|
14
14
|
gem "guard"
|
|
15
15
|
gem "guard-rspec"
|
|
16
|
-
|
|
17
|
-
gem "perftools.rb"
|
|
@@ -4,9 +4,9 @@ source "http://rubygems.org"
|
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem 'rails', '3.1.
|
|
7
|
+
gem 'rails', '3.1.11'
|
|
8
8
|
gem 'sqlite3'
|
|
9
|
-
gem '
|
|
9
|
+
gem 'mysql2'
|
|
10
10
|
gem 'activerecord-import'
|
|
11
11
|
gem 'mongoid', '2.4.12'
|
|
12
12
|
gem 'bson_ext'
|
|
@@ -14,5 +14,3 @@ gem 'bson_ext'
|
|
|
14
14
|
gem "rspec"
|
|
15
15
|
gem "guard"
|
|
16
16
|
gem "guard-rspec"
|
|
17
|
-
|
|
18
|
-
gem "perftools.rb"
|
|
@@ -4,9 +4,9 @@ source "http://rubygems.org"
|
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem 'rails', '3.2.
|
|
7
|
+
gem 'rails', '3.2.12'
|
|
8
8
|
gem 'sqlite3'
|
|
9
|
-
gem '
|
|
9
|
+
gem 'mysql2'
|
|
10
10
|
gem 'activerecord-import'
|
|
11
11
|
gem 'mongoid', '2.5.1'
|
|
12
12
|
gem 'bson_ext'
|
|
@@ -14,5 +14,3 @@ gem 'bson_ext'
|
|
|
14
14
|
gem "rspec"
|
|
15
15
|
gem "guard"
|
|
16
16
|
gem "guard-rspec"
|
|
17
|
-
|
|
18
|
-
gem "perftools.rb"
|
data/Gemfile.rails-4-beta
CHANGED
|
@@ -4,15 +4,11 @@ source "http://rubygems.org"
|
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem 'rails',
|
|
8
|
-
gem 'journey', github: 'rails/journey'
|
|
9
|
-
gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
|
|
7
|
+
gem 'rails', '4.0.0.beta1'
|
|
10
8
|
gem 'sqlite3'
|
|
11
|
-
gem '
|
|
9
|
+
gem 'mysql2'
|
|
12
10
|
gem 'activerecord-import'
|
|
13
11
|
|
|
14
12
|
gem "rspec"
|
|
15
13
|
gem "guard"
|
|
16
14
|
gem "guard-rspec"
|
|
17
|
-
|
|
18
|
-
gem "perftools.rb"
|
data/README.textile
CHANGED
|
@@ -51,7 +51,6 @@ config.after_initialize do
|
|
|
51
51
|
:show_online_status => true }
|
|
52
52
|
Bullet.rails_logger = true
|
|
53
53
|
Bullet.airbrake = true
|
|
54
|
-
Bullet.disable_browser_cache = true
|
|
55
54
|
end
|
|
56
55
|
</code></pre>
|
|
57
56
|
|
|
@@ -66,7 +65,6 @@ The code above will enable all seven of the Bullet notification systems:
|
|
|
66
65
|
* <code>Bullet.console</code>: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
|
67
66
|
* <code>Bullet.growl</code>: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
68
67
|
* <code>Bullet.xmpp</code>: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the bullet account won't announce it's online status anymore.
|
|
69
|
-
* <code>Bullet.disable_browser_cache</code>: disable browser cache which usually causes unexpected problems
|
|
70
68
|
|
|
71
69
|
****************************************************************************
|
|
72
70
|
|
|
@@ -122,11 +120,10 @@ The bullet gem use rack middleware for http request. If you want to bullet for w
|
|
|
122
120
|
<pre><code>
|
|
123
121
|
Bullet.start_request if Bullet.enable?
|
|
124
122
|
# run job
|
|
125
|
-
if Bullet.enable?
|
|
126
|
-
Bullet.
|
|
127
|
-
Bullet.log_notification('JobServer: ')
|
|
128
|
-
Bullet.end_request
|
|
123
|
+
if Bullet.enable? && Bullet.notification?
|
|
124
|
+
Bullet.perform_out_of_channel_notifications
|
|
129
125
|
end
|
|
126
|
+
Bullet.end_request if Bullet.enable?
|
|
130
127
|
</code></pre>
|
|
131
128
|
|
|
132
129
|
Or you want to use it in test mode
|
|
@@ -137,10 +134,10 @@ before(:each)
|
|
|
137
134
|
end
|
|
138
135
|
|
|
139
136
|
after(:each)
|
|
140
|
-
if Bullet.enable?
|
|
137
|
+
if Bullet.enable? && Bullet.notification?
|
|
141
138
|
Bullet.perform_out_of_channel_notifications
|
|
142
|
-
Bullet.end_request
|
|
143
139
|
end
|
|
140
|
+
Bullet.end_request if Bullet.enable?
|
|
144
141
|
end
|
|
145
142
|
</code></pre>
|
|
146
143
|
|
|
@@ -225,7 +222,6 @@ config.after_initialize do
|
|
|
225
222
|
Bullet.console = true
|
|
226
223
|
# Bullet.growl = true
|
|
227
224
|
Bullet.rails_logger = true
|
|
228
|
-
Bullet.disable_browser_cache = true
|
|
229
225
|
end
|
|
230
226
|
</code></pre>
|
|
231
227
|
|
|
@@ -374,4 +370,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
|
|
|
374
370
|
****************************************************************************
|
|
375
371
|
|
|
376
372
|
|
|
377
|
-
Copyright (c) 2009 -
|
|
373
|
+
Copyright (c) 2009 - 2013 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/README_for_rails2.textile
CHANGED
|
@@ -44,7 +44,6 @@ config.after_initialize do
|
|
|
44
44
|
Bullet.console = true
|
|
45
45
|
Bullet.growl = true
|
|
46
46
|
Bullet.rails_logger = true
|
|
47
|
-
Bullet.disable_browser_cache = true
|
|
48
47
|
Bullet.xmpp = { :account => 'bullets_account@jabber.org',
|
|
49
48
|
:password => 'bullets_password_for_jabber',
|
|
50
49
|
:receiver => 'your_account@jabber.org',
|
|
@@ -61,7 +60,6 @@ The code above will enable all five of the Bullet notification systems:
|
|
|
61
60
|
* <code>Bullet.rails_logger</code>: add warnings directly to the Rails log
|
|
62
61
|
* <code>Bullet.console</code>: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
|
63
62
|
* <code>Bullet.growl</code>: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
64
|
-
* <code>Bullet.disable_browser_cache</code>: disable browser cache which usually causes unexpected problems
|
|
65
63
|
|
|
66
64
|
****************************************************************************
|
|
67
65
|
|
|
@@ -152,11 +150,10 @@ The bullet plugin/gem use rack middleware for http request. If you want to bulle
|
|
|
152
150
|
<pre><code>
|
|
153
151
|
Bullet.start_request if Bullet.enable?
|
|
154
152
|
# run job
|
|
155
|
-
if Bullet.enable?
|
|
156
|
-
Bullet.
|
|
157
|
-
Bullet.log_notification('JobServer: ')
|
|
158
|
-
Bullet.end_request
|
|
153
|
+
if Bullet.enable? && Bullet.notification?
|
|
154
|
+
Bullet.perform_out_of_channel_notifications
|
|
159
155
|
end
|
|
156
|
+
Bullet.end_request if Bullet.enable?
|
|
160
157
|
</code></pre>
|
|
161
158
|
|
|
162
159
|
Or you want to use it in test mode
|
|
@@ -167,10 +164,10 @@ before(:each)
|
|
|
167
164
|
end
|
|
168
165
|
|
|
169
166
|
after(:each)
|
|
170
|
-
if Bullet.enable?
|
|
167
|
+
if Bullet.enable? && Bullet.notification?
|
|
171
168
|
Bullet.perform_out_of_channel_notifications
|
|
172
|
-
Bullet.end_request
|
|
173
169
|
end
|
|
170
|
+
Bullet.end_request if Bullet.enable?
|
|
174
171
|
end
|
|
175
172
|
</code></pre>
|
|
176
173
|
|
|
@@ -253,7 +250,6 @@ config.after_initialize do
|
|
|
253
250
|
Bullet.console = true
|
|
254
251
|
# Bullet.growl = true
|
|
255
252
|
Bullet.rails_logger = true
|
|
256
|
-
Bullet.disable_browser_cache = true
|
|
257
253
|
end
|
|
258
254
|
</code></pre>
|
|
259
255
|
|
|
@@ -401,4 +397,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
|
|
|
401
397
|
****************************************************************************
|
|
402
398
|
|
|
403
399
|
|
|
404
|
-
Copyright (c) 2009 -
|
|
400
|
+
Copyright (c) 2009 - 2013 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
|
@@ -23,8 +23,8 @@ module Bullet
|
|
|
23
23
|
# include query for one to many associations.
|
|
24
24
|
# keep this eager loadings.
|
|
25
25
|
alias_method :origin_initialize, :initialize
|
|
26
|
-
def initialize(records, associations,
|
|
27
|
-
origin_initialize(records, associations,
|
|
26
|
+
def initialize(records, associations, preload_scope = nil)
|
|
27
|
+
origin_initialize(records, associations, preload_scope)
|
|
28
28
|
records = [records].flatten.compact.uniq
|
|
29
29
|
return if records.empty?
|
|
30
30
|
records.each do |record|
|
|
@@ -39,7 +39,7 @@ module Bullet
|
|
|
39
39
|
alias_method :origin_find_with_associations, :find_with_associations
|
|
40
40
|
def find_with_associations
|
|
41
41
|
records = origin_find_with_associations
|
|
42
|
-
associations = (
|
|
42
|
+
associations = (eager_load_values + includes_values).uniq
|
|
43
43
|
records.each do |record|
|
|
44
44
|
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
45
45
|
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Bullet
|
|
2
|
+
module ActiveRecord
|
|
3
|
+
def self.enable
|
|
4
|
+
require 'active_record'
|
|
5
|
+
::ActiveRecord::Relation.class_eval do
|
|
6
|
+
alias_method :origin_to_a, :to_a
|
|
7
|
+
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
|
8
|
+
# if select only one object, then the only one object has impossible to cause N+1 query.
|
|
9
|
+
def to_a
|
|
10
|
+
records = origin_to_a
|
|
11
|
+
if records.size > 1
|
|
12
|
+
Bullet::Detector::Association.add_possible_objects(records)
|
|
13
|
+
Bullet::Detector::Counter.add_possible_objects(records)
|
|
14
|
+
elsif records.size == 1
|
|
15
|
+
Bullet::Detector::Association.add_impossible_object(records.first)
|
|
16
|
+
Bullet::Detector::Counter.add_impossible_object(records.first)
|
|
17
|
+
end
|
|
18
|
+
records
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
::ActiveRecord::Associations::Preloader.class_eval do
|
|
23
|
+
# include query for one to many associations.
|
|
24
|
+
# keep this eager loadings.
|
|
25
|
+
alias_method :origin_initialize, :initialize
|
|
26
|
+
def initialize(records, associations, preload_scope = nil)
|
|
27
|
+
origin_initialize(records, associations, preload_scope)
|
|
28
|
+
records = [records].flatten.compact.uniq
|
|
29
|
+
return if records.empty?
|
|
30
|
+
records.each do |record|
|
|
31
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
32
|
+
end
|
|
33
|
+
Bullet::Detector::Association.add_eager_loadings(records, associations)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
::ActiveRecord::FinderMethods.class_eval do
|
|
38
|
+
# add includes in scope
|
|
39
|
+
alias_method :origin_find_with_associations, :find_with_associations
|
|
40
|
+
def find_with_associations
|
|
41
|
+
records = origin_find_with_associations
|
|
42
|
+
associations = (eager_load_values + includes_values).uniq
|
|
43
|
+
records.each do |record|
|
|
44
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
45
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
|
46
|
+
end
|
|
47
|
+
Bullet::Detector::Association.add_eager_loadings(records, associations)
|
|
48
|
+
records
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
::ActiveRecord::Associations::JoinDependency.class_eval do
|
|
53
|
+
alias_method :origin_construct_association, :construct_association
|
|
54
|
+
# call join associations
|
|
55
|
+
def construct_association(record, join, row)
|
|
56
|
+
associations = join.reflection.name
|
|
57
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
58
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
|
59
|
+
origin_construct_association(record, join, row)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
::ActiveRecord::Associations::CollectionAssociation.class_eval do
|
|
64
|
+
# call one to many associations
|
|
65
|
+
alias_method :origin_load_target, :load_target
|
|
66
|
+
def load_target
|
|
67
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
68
|
+
origin_load_target
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
::ActiveRecord::Associations::SingularAssociation.class_eval do
|
|
73
|
+
# call has_one and belongs_to associations
|
|
74
|
+
alias_method :origin_reader, :reader
|
|
75
|
+
def reader(force_reload = false)
|
|
76
|
+
result = origin_reader(force_reload)
|
|
77
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
78
|
+
Bullet::Detector::Association.add_possible_objects(result)
|
|
79
|
+
result
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
84
|
+
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
|
85
|
+
|
|
86
|
+
def has_cached_counter?(reflection = reflection)
|
|
87
|
+
result = origin_has_cached_counter?(reflection)
|
|
88
|
+
Bullet::Detector::Counter.add_counter_cache(owner, reflection.name) unless result
|
|
89
|
+
result
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/lib/bullet/dependency.rb
CHANGED
|
@@ -24,8 +24,10 @@ module Bullet
|
|
|
24
24
|
'active_record2'
|
|
25
25
|
elsif active_record30?
|
|
26
26
|
'active_record3'
|
|
27
|
-
elsif active_record31? || active_record32?
|
|
27
|
+
elsif active_record31? || active_record32?
|
|
28
28
|
'active_record3x'
|
|
29
|
+
elsif active_record4?
|
|
30
|
+
'active_record4'
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
data/lib/bullet/rack.rb
CHANGED
|
@@ -20,7 +20,6 @@ module Bullet
|
|
|
20
20
|
Bullet.perform_out_of_channel_notifications(env)
|
|
21
21
|
end
|
|
22
22
|
Bullet.end_request
|
|
23
|
-
no_browser_cache(headers) if Bullet.disable_browser_cache
|
|
24
23
|
[status, headers, response_body ? [response_body] : response]
|
|
25
24
|
end
|
|
26
25
|
|
|
@@ -28,7 +27,9 @@ module Bullet
|
|
|
28
27
|
def empty?(response)
|
|
29
28
|
# response may be ["Not Found"], ["Move Permanently"], etc.
|
|
30
29
|
(response.is_a?(Array) && response.size <= 1) ||
|
|
31
|
-
!response.respond_to?(:body) ||
|
|
30
|
+
!response.respond_to?(:body) ||
|
|
31
|
+
!response.body.respond_to?(:empty?) ||
|
|
32
|
+
response.body.empty?
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
# if send file?
|
|
@@ -39,11 +40,5 @@ module Bullet
|
|
|
39
40
|
def html_request?(headers, response)
|
|
40
41
|
headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response.body.include?("<html")
|
|
41
42
|
end
|
|
42
|
-
|
|
43
|
-
def no_browser_cache(headers)
|
|
44
|
-
headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
|
45
|
-
headers["Pragma"] = "no-cache"
|
|
46
|
-
headers["Expires"] = "Wed, 09 Sep 2009 09:09:09 GMT"
|
|
47
|
-
end
|
|
48
43
|
end
|
|
49
44
|
end
|
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
data/perf/benchmark.rb
CHANGED
|
@@ -27,7 +27,7 @@ class User < ActiveRecord::Base
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# create database bullet_benchmark;
|
|
30
|
-
ActiveRecord::Base.establish_connection(:adapter => '
|
|
30
|
+
ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'bullet_benchmark', :server => '/tmp/mysql.socket', :username => 'root')
|
|
31
31
|
|
|
32
32
|
ActiveRecord::Base.connection.tables.each do |table|
|
|
33
33
|
ActiveRecord::Base.connection.drop_table(table)
|
|
@@ -79,8 +79,6 @@ puts "Start benchmarking..."
|
|
|
79
79
|
|
|
80
80
|
Bullet.enable = true
|
|
81
81
|
|
|
82
|
-
PerfTools::CpuProfiler.start(ARGV[0]|| "benchmark_profile") if defined? PerfTools
|
|
83
|
-
|
|
84
82
|
Benchmark.bm(70) do |bm|
|
|
85
83
|
bm.report("Querying & Iterating #{posts_size} Posts with #{comments_size} Comments and #{users_size} Users") do
|
|
86
84
|
10.times do
|
|
@@ -98,7 +96,6 @@ Benchmark.bm(70) do |bm|
|
|
|
98
96
|
end
|
|
99
97
|
end
|
|
100
98
|
|
|
101
|
-
PerfTools::CpuProfiler.stop if defined? PerfTools
|
|
102
99
|
puts "End benchmarking..."
|
|
103
100
|
|
|
104
101
|
|
data/spec/bullet/rack_spec.rb
CHANGED
|
@@ -6,16 +6,6 @@ module Bullet
|
|
|
6
6
|
let(:middleware) { Bullet::Rack.new app }
|
|
7
7
|
let(:app) { Support::AppDouble.new }
|
|
8
8
|
|
|
9
|
-
context "#no_browser_cache" do
|
|
10
|
-
it "should add no cache meta in http headers" do
|
|
11
|
-
headers = {}
|
|
12
|
-
middleware.no_browser_cache(headers)
|
|
13
|
-
headers["Cache-Control"].should == "no-cache, no-store, max-age=0, must-revalidate"
|
|
14
|
-
headers["Pragma"].should == "no-cache"
|
|
15
|
-
headers["Expires"].should == "Wed, 09 Sep 2009 09:09:09 GMT"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
9
|
context "#html_request?" do
|
|
20
10
|
it "should be true if Content-Type is text/html and http body contains html tag" do
|
|
21
11
|
headers = {"Content-Type" => "text/html"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
if active_record3?
|
|
3
|
+
if active_record3? || active_record4?
|
|
4
4
|
describe Bullet::Detector::Association, 'has_many' do
|
|
5
5
|
before(:each) do
|
|
6
6
|
Bullet.clear
|
|
@@ -66,7 +66,7 @@ if active_record3?
|
|
|
66
66
|
it "should detect preload category => posts, but no post => comments" do
|
|
67
67
|
Category.includes(:posts).each do |category|
|
|
68
68
|
category.posts.each do |post|
|
|
69
|
-
post.comments.
|
|
69
|
+
post.comments.map(&:name)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
@@ -176,7 +176,7 @@ if active_record3?
|
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
it "should detect preload with post => commnets" do
|
|
179
|
-
Post.first.comments.
|
|
179
|
+
Post.first.comments.map(&:name)
|
|
180
180
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
181
181
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
182
182
|
|
|
@@ -199,7 +199,7 @@ if active_record3?
|
|
|
199
199
|
|
|
200
200
|
context "scope for_category_name" do
|
|
201
201
|
it "should detect preload with post => category" do
|
|
202
|
-
Post.in_category_name('first').
|
|
202
|
+
Post.in_category_name('first').each do |post|
|
|
203
203
|
post.category.name
|
|
204
204
|
end
|
|
205
205
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
@@ -278,7 +278,7 @@ if active_record3?
|
|
|
278
278
|
end
|
|
279
279
|
|
|
280
280
|
it "should not detect preload with comment => post" do
|
|
281
|
-
Comment.all.
|
|
281
|
+
Comment.all.map(&:name)
|
|
282
282
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
283
283
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
284
284
|
|
|
@@ -415,7 +415,7 @@ if active_record3?
|
|
|
415
415
|
end
|
|
416
416
|
|
|
417
417
|
it "should detect no unused preload associations" do
|
|
418
|
-
Student.all.
|
|
418
|
+
Student.all.map(&:name)
|
|
419
419
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
420
420
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
421
421
|
|
|
@@ -456,7 +456,7 @@ if active_record3?
|
|
|
456
456
|
end
|
|
457
457
|
|
|
458
458
|
it "should not detect preload associations" do
|
|
459
|
-
Firm.all.
|
|
459
|
+
Firm.all.map(&:name)
|
|
460
460
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
461
461
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
462
462
|
|
|
@@ -464,7 +464,7 @@ if active_record3?
|
|
|
464
464
|
end
|
|
465
465
|
|
|
466
466
|
it "should detect unused preload associations" do
|
|
467
|
-
Firm.includes(:clients).
|
|
467
|
+
Firm.includes(:clients).map(&:name)
|
|
468
468
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
469
469
|
Bullet::Detector::Association.should be_unused_preload_associations_for(Firm, :clients)
|
|
470
470
|
|
|
@@ -495,7 +495,7 @@ if active_record3?
|
|
|
495
495
|
end
|
|
496
496
|
|
|
497
497
|
it "should detect preload association" do
|
|
498
|
-
Company.
|
|
498
|
+
Company.includes(:address).each do |company|
|
|
499
499
|
company.address.name
|
|
500
500
|
end
|
|
501
501
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
@@ -505,7 +505,7 @@ if active_record3?
|
|
|
505
505
|
end
|
|
506
506
|
|
|
507
507
|
it "should not detect preload association" do
|
|
508
|
-
Company.all.
|
|
508
|
+
Company.all.map(&:name)
|
|
509
509
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
510
510
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
511
511
|
|
|
@@ -513,7 +513,7 @@ if active_record3?
|
|
|
513
513
|
end
|
|
514
514
|
|
|
515
515
|
it "should detect unused preload association" do
|
|
516
|
-
Company.
|
|
516
|
+
Company.includes(:address).map(&:name)
|
|
517
517
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
518
518
|
Bullet::Detector::Association.should be_unused_preload_associations_for(Company, :address)
|
|
519
519
|
|
|
@@ -564,7 +564,7 @@ if active_record3?
|
|
|
564
564
|
end
|
|
565
565
|
|
|
566
566
|
it "should detect preload associations" do
|
|
567
|
-
Page.
|
|
567
|
+
Page.includes(:author).each do |page|
|
|
568
568
|
page.author.name
|
|
569
569
|
end
|
|
570
570
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
@@ -574,7 +574,7 @@ if active_record3?
|
|
|
574
574
|
end
|
|
575
575
|
|
|
576
576
|
it "should detect unused preload associations" do
|
|
577
|
-
Page.
|
|
577
|
+
Page.includes(:author).map(&:name)
|
|
578
578
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
579
579
|
Bullet::Detector::Association.should be_unused_preload_associations_for(Page, :author)
|
|
580
580
|
|
|
@@ -582,7 +582,7 @@ if active_record3?
|
|
|
582
582
|
end
|
|
583
583
|
|
|
584
584
|
it "should not detect preload associations" do
|
|
585
|
-
Page.all.
|
|
585
|
+
Page.all.map(&:name)
|
|
586
586
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
587
587
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
588
588
|
|
data/test.sh
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
bundle && bundle exec rspec spec
|
|
2
|
-
BUNDLE_GEMFILE=Gemfile.rails-3.2.
|
|
3
|
-
BUNDLE_GEMFILE=Gemfile.rails-3.1.
|
|
4
|
-
BUNDLE_GEMFILE=Gemfile.rails-3.0.
|
|
5
|
-
BUNDLE_GEMFILE=Gemfile.rails-2.3.
|
|
2
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.2.12 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2.12 bundle exec rspec spec
|
|
3
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.1.11 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.1.11 bundle exec rspec spec
|
|
4
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.0.20 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.0.20 bundle exec rspec spec
|
|
5
|
+
BUNDLE_GEMFILE=Gemfile.rails-2.3.17 bundle && BUNDLE_GEMFILE=Gemfile.rails-2.3.17 bundle exec rspec spec
|
|
6
6
|
BUNDLE_GEMFILE=Gemfile.rails-4-beta bundle && BUNDLE_GEMFILE=Gemfile.rails-4-beta bundle exec rspec spec
|
metadata
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 4.4.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Richard Huang
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2013-03-15 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: uniform_notifier
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
16
|
requirements:
|
|
19
|
-
- -
|
|
17
|
+
- - '>='
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
19
|
version: '0'
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
23
|
requirements:
|
|
27
|
-
- -
|
|
24
|
+
- - '>='
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
26
|
version: '0'
|
|
30
27
|
description: A rails plugin to kill N+1 queries and unused eager loading.
|
|
@@ -40,10 +37,10 @@ files:
|
|
|
40
37
|
- .rvmrc.example
|
|
41
38
|
- .travis.yml
|
|
42
39
|
- Gemfile
|
|
43
|
-
- Gemfile.rails-2.3.
|
|
44
|
-
- Gemfile.rails-3.0.
|
|
45
|
-
- Gemfile.rails-3.1.
|
|
46
|
-
- Gemfile.rails-3.2.
|
|
40
|
+
- Gemfile.rails-2.3.17
|
|
41
|
+
- Gemfile.rails-3.0.20
|
|
42
|
+
- Gemfile.rails-3.1.11
|
|
43
|
+
- Gemfile.rails-3.2.12
|
|
47
44
|
- Gemfile.rails-4-beta
|
|
48
45
|
- Guardfile
|
|
49
46
|
- Hacking.textile
|
|
@@ -57,6 +54,7 @@ files:
|
|
|
57
54
|
- lib/bullet/active_record2.rb
|
|
58
55
|
- lib/bullet/active_record3.rb
|
|
59
56
|
- lib/bullet/active_record3x.rb
|
|
57
|
+
- lib/bullet/active_record4.rb
|
|
60
58
|
- lib/bullet/dependency.rb
|
|
61
59
|
- lib/bullet/detector.rb
|
|
62
60
|
- lib/bullet/detector/association.rb
|
|
@@ -143,30 +141,26 @@ files:
|
|
|
143
141
|
- test.sh
|
|
144
142
|
homepage: http://github.com/flyerhzm/bullet
|
|
145
143
|
licenses: []
|
|
144
|
+
metadata: {}
|
|
146
145
|
post_install_message:
|
|
147
146
|
rdoc_options: []
|
|
148
147
|
require_paths:
|
|
149
148
|
- lib
|
|
150
149
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
|
-
none: false
|
|
152
150
|
requirements:
|
|
153
|
-
- -
|
|
151
|
+
- - '>='
|
|
154
152
|
- !ruby/object:Gem::Version
|
|
155
153
|
version: '0'
|
|
156
|
-
segments:
|
|
157
|
-
- 0
|
|
158
|
-
hash: 197998252985008423
|
|
159
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
|
-
none: false
|
|
161
155
|
requirements:
|
|
162
|
-
- -
|
|
156
|
+
- - '>='
|
|
163
157
|
- !ruby/object:Gem::Version
|
|
164
158
|
version: 1.3.6
|
|
165
159
|
requirements: []
|
|
166
160
|
rubyforge_project:
|
|
167
|
-
rubygems_version:
|
|
161
|
+
rubygems_version: 2.0.2
|
|
168
162
|
signing_key:
|
|
169
|
-
specification_version:
|
|
163
|
+
specification_version: 4
|
|
170
164
|
summary: A rails plugin to kill N+1 queries and unused eager loading.
|
|
171
165
|
test_files:
|
|
172
166
|
- spec/bullet/detector/association_spec.rb
|