bullet 7.0.7 → 7.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -1
- data/README.md +6 -3
- data/lib/bullet/active_record4.rb +10 -0
- data/lib/bullet/active_record41.rb +10 -0
- data/lib/bullet/active_record42.rb +10 -0
- data/lib/bullet/active_record5.rb +18 -0
- data/lib/bullet/active_record52.rb +18 -0
- data/lib/bullet/active_record60.rb +18 -0
- data/lib/bullet/active_record61.rb +18 -0
- data/lib/bullet/active_record70.rb +32 -8
- data/lib/bullet/active_record71.rb +308 -0
- data/lib/bullet/dependency.rb +12 -0
- data/lib/bullet/detector/n_plus_one_query.rb +2 -5
- data/lib/bullet/detector/unused_eager_loading.rb +5 -2
- data/lib/bullet/ext/object.rb +14 -3
- data/lib/bullet/mongoid8x.rb +59 -0
- data/lib/bullet/notification/base.rb +9 -8
- data/lib/bullet/notification/counter_cache.rb +1 -1
- data/lib/bullet/rack.rb +4 -2
- data/lib/bullet/registry/association.rb +2 -1
- data/lib/bullet/stack_trace_filter.rb +3 -2
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +7 -2
- metadata +7 -155
- data/.github/workflows/main.yml +0 -82
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/Gemfile +0 -24
- data/Gemfile.mongoid +0 -12
- data/Gemfile.mongoid-4.0 +0 -15
- data/Gemfile.mongoid-5.0 +0 -15
- data/Gemfile.mongoid-6.0 +0 -15
- data/Gemfile.mongoid-7.0 +0 -15
- data/Gemfile.rails-4.0 +0 -16
- data/Gemfile.rails-4.1 +0 -16
- data/Gemfile.rails-4.2 +0 -16
- data/Gemfile.rails-5.0 +0 -15
- data/Gemfile.rails-5.1 +0 -15
- data/Gemfile.rails-5.2 +0 -15
- data/Gemfile.rails-6.0 +0 -15
- data/Gemfile.rails-6.1 +0 -15
- data/Gemfile.rails-7.0 +0 -10
- data/Guardfile +0 -8
- data/Hacking.md +0 -75
- data/Rakefile +0 -51
- data/bullet.gemspec +0 -33
- data/perf/benchmark.rb +0 -118
- data/rails/init.rb +0 -3
- data/spec/bullet/detector/association_spec.rb +0 -28
- data/spec/bullet/detector/base_spec.rb +0 -10
- data/spec/bullet/detector/counter_cache_spec.rb +0 -58
- data/spec/bullet/detector/n_plus_one_query_spec.rb +0 -150
- data/spec/bullet/detector/unused_eager_loading_spec.rb +0 -126
- data/spec/bullet/ext/object_spec.rb +0 -44
- data/spec/bullet/ext/string_spec.rb +0 -15
- data/spec/bullet/notification/base_spec.rb +0 -94
- data/spec/bullet/notification/counter_cache_spec.rb +0 -14
- data/spec/bullet/notification/n_plus_one_query_spec.rb +0 -29
- data/spec/bullet/notification/unused_eager_loading_spec.rb +0 -18
- data/spec/bullet/notification_collector_spec.rb +0 -34
- data/spec/bullet/rack_spec.rb +0 -296
- data/spec/bullet/registry/association_spec.rb +0 -28
- data/spec/bullet/registry/base_spec.rb +0 -46
- data/spec/bullet/registry/object_spec.rb +0 -26
- data/spec/bullet/stack_trace_filter_spec.rb +0 -26
- data/spec/bullet_spec.rb +0 -136
- data/spec/integration/active_record/association_spec.rb +0 -822
- data/spec/integration/counter_cache_spec.rb +0 -68
- data/spec/integration/mongoid/association_spec.rb +0 -246
- data/spec/models/address.rb +0 -5
- data/spec/models/attachment.rb +0 -5
- data/spec/models/author.rb +0 -5
- data/spec/models/base_user.rb +0 -7
- data/spec/models/category.rb +0 -12
- data/spec/models/city.rb +0 -5
- data/spec/models/client.rb +0 -8
- data/spec/models/comment.rb +0 -8
- data/spec/models/company.rb +0 -5
- data/spec/models/country.rb +0 -5
- data/spec/models/deal.rb +0 -5
- data/spec/models/document.rb +0 -7
- data/spec/models/entry.rb +0 -5
- data/spec/models/firm.rb +0 -7
- data/spec/models/folder.rb +0 -4
- data/spec/models/group.rb +0 -4
- data/spec/models/mongoid/address.rb +0 -9
- data/spec/models/mongoid/category.rb +0 -10
- data/spec/models/mongoid/comment.rb +0 -9
- data/spec/models/mongoid/company.rb +0 -9
- data/spec/models/mongoid/entry.rb +0 -9
- data/spec/models/mongoid/post.rb +0 -14
- data/spec/models/mongoid/user.rb +0 -7
- data/spec/models/newspaper.rb +0 -5
- data/spec/models/page.rb +0 -4
- data/spec/models/person.rb +0 -5
- data/spec/models/pet.rb +0 -5
- data/spec/models/post.rb +0 -34
- data/spec/models/relationship.rb +0 -6
- data/spec/models/reply.rb +0 -5
- data/spec/models/role.rb +0 -7
- data/spec/models/student.rb +0 -5
- data/spec/models/submission.rb +0 -7
- data/spec/models/teacher.rb +0 -5
- data/spec/models/user.rb +0 -8
- data/spec/models/writer.rb +0 -4
- data/spec/spec_helper.rb +0 -97
- data/spec/support/bullet_ext.rb +0 -56
- data/spec/support/mongo_seed.rb +0 -59
- data/spec/support/rack_double.rb +0 -49
- data/spec/support/sqlite_seed.rb +0 -284
- data/test.sh +0 -15
- data/update.sh +0 -10
data/Gemfile.rails-4.1
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 4.1.0'
|
6
|
-
gem 'sqlite3', '~> 1.3.6'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
|
10
|
-
|
11
|
-
gem "rspec"
|
12
|
-
|
13
|
-
platforms :rbx do
|
14
|
-
gem 'rubysl', '~> 2.0'
|
15
|
-
gem 'rubinius-developer_tools'
|
16
|
-
end
|
data/Gemfile.rails-4.2
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 4.2.0'
|
6
|
-
gem 'sqlite3', '~> 1.3.6'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
|
10
|
-
|
11
|
-
gem "rspec"
|
12
|
-
|
13
|
-
platforms :rbx do
|
14
|
-
gem 'rubysl', '~> 2.0'
|
15
|
-
gem 'rubinius-developer_tools'
|
16
|
-
end
|
data/Gemfile.rails-5.0
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 5.0.0'
|
6
|
-
gem 'sqlite3', '~> 1.3.6'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
|
10
|
-
gem "rspec"
|
11
|
-
|
12
|
-
platforms :rbx do
|
13
|
-
gem 'rubysl', '~> 2.0'
|
14
|
-
gem 'rubinius-developer_tools'
|
15
|
-
end
|
data/Gemfile.rails-5.1
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 5.1.0'
|
6
|
-
gem 'sqlite3', '~> 1.3.6'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
|
10
|
-
gem "rspec"
|
11
|
-
|
12
|
-
platforms :rbx do
|
13
|
-
gem 'rubysl', '~> 2.0'
|
14
|
-
gem 'rubinius-developer_tools'
|
15
|
-
end
|
data/Gemfile.rails-5.2
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 5.2.0'
|
6
|
-
gem 'sqlite3', '~> 1.3.6'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
|
10
|
-
gem "rspec"
|
11
|
-
|
12
|
-
platforms :rbx do
|
13
|
-
gem 'rubysl', '~> 2.0'
|
14
|
-
gem 'rubinius-developer_tools'
|
15
|
-
end
|
data/Gemfile.rails-6.0
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 6.0.0'
|
6
|
-
gem 'sqlite3'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
|
10
|
-
gem "rspec"
|
11
|
-
|
12
|
-
platforms :rbx do
|
13
|
-
gem 'rubysl', '~> 2.0'
|
14
|
-
gem 'rubinius-developer_tools'
|
15
|
-
end
|
data/Gemfile.rails-6.1
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rails', '~> 6.1.0'
|
6
|
-
gem 'sqlite3'
|
7
|
-
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'activerecord-import'
|
9
|
-
|
10
|
-
gem "rspec"
|
11
|
-
|
12
|
-
platforms :rbx do
|
13
|
-
gem 'rubysl', '~> 2.0'
|
14
|
-
gem 'rubinius-developer_tools'
|
15
|
-
end
|
data/Gemfile.rails-7.0
DELETED
data/Guardfile
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
# A sample Guardfile
|
2
|
-
# More info at https://github.com/guard/guard#readme
|
3
|
-
|
4
|
-
guard 'rspec', version: 2, all_after_pass: false, all_on_start: false, cli: '--color --format nested --fail-fast' do
|
5
|
-
watch(%r{^spec/.+_spec\.rb$})
|
6
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
-
watch('spec/spec_helper.rb') { 'spec' }
|
8
|
-
end
|
data/Hacking.md
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# Bullet Overview for Developers
|
2
|
-
|
3
|
-
This file aims to give developers a quick tour of the bullet internals, making
|
4
|
-
it (hopefully) easier to extend or enhance the Bullet gem.
|
5
|
-
|
6
|
-
## General Control Flow aka. 10000 Meter View
|
7
|
-
|
8
|
-
When Rails is initialized, Bullet will extend ActiveRecord (and if you're using
|
9
|
-
Rails 2.x ActiveController too) with the relevant modules and methods found
|
10
|
-
in lib/bullet/active_recordX.rb and lib/bullet/action_controller2.rb. If you're
|
11
|
-
running Rails 3, Bullet will integrate itself as a middleware into the Rack
|
12
|
-
stack, so ActionController does not need to be extended.
|
13
|
-
|
14
|
-
The ActiveRecord extensions will call methods in a given detector class, when
|
15
|
-
certain methods are called.
|
16
|
-
|
17
|
-
Detector classes contain all the logic to recognize
|
18
|
-
a noteworthy event. If such an event is detected, an instance of the
|
19
|
-
corresponding Notification class is created and stored in a Set instance in the
|
20
|
-
main Bullet module (the 'notification collector').
|
21
|
-
|
22
|
-
Notification instances contain the message that will be displayed, and will
|
23
|
-
use a Presenter class to display their message to the user.
|
24
|
-
|
25
|
-
So the flow of a request goes like this:
|
26
|
-
|
27
|
-
1. Bullet.start_request is called, which resets all the detectors and empties
|
28
|
-
the notification collector
|
29
|
-
2. The request is handled by Rails, and the installed ActiveRecord extensions
|
30
|
-
trigger Detector callbacks
|
31
|
-
3. Detectors once called, will determine whether something noteworthy happened.
|
32
|
-
If yes, then a Notification is created and stored in the notification collector.
|
33
|
-
4. Rails finishes handling the request
|
34
|
-
5. For each notification in the collector, Bullet will iterate over each
|
35
|
-
Presenter and will try to generate an inline message that will be appended to
|
36
|
-
the generated response body.
|
37
|
-
6. The response is returned to the client.
|
38
|
-
7. Bullet will try to generate an out-of-channel message for each notification.
|
39
|
-
8. Bullet calls end_request for each detector.
|
40
|
-
9. Goto 1.
|
41
|
-
|
42
|
-
## Adding Notification Types
|
43
|
-
|
44
|
-
If you want to add more kinds of things that Bullet can detect, a little more
|
45
|
-
work is needed than if you were just adding a Presenter, but the concepts are
|
46
|
-
similar.
|
47
|
-
|
48
|
-
* Add the class to the DETECTORS constant in the main Bullet module
|
49
|
-
* Add (if needed) Rails monkey patches to Bullet.enable
|
50
|
-
* Add an autoload directive to lib/bullet/detector.rb
|
51
|
-
* Create a corresponding notification class in the Bullet::Notification namespace
|
52
|
-
* Add an autoload directive to lib/bullet/notification.rb
|
53
|
-
|
54
|
-
As a rule of thumb, you can assume that each Detector will have its own
|
55
|
-
Notification class. If you follow the principle of Separation of Concerns I
|
56
|
-
can't really think of an example where one would deviate from this rule.
|
57
|
-
|
58
|
-
Since the detection of pathological associations is a bit hairy, I'd recommend
|
59
|
-
having a look at the counter cache detector and associated notification to get
|
60
|
-
a feel for what is needed to get off the ground.
|
61
|
-
|
62
|
-
### Detectors
|
63
|
-
|
64
|
-
The only things you'll need to consider when building your Detector class is
|
65
|
-
that it will need to supply the .start_request, .end_request and .clear class
|
66
|
-
methods.
|
67
|
-
|
68
|
-
Simple implementations are provided by Bullet::Detector::Base for start_request
|
69
|
-
and end_request, you will have to supply your own clear method.
|
70
|
-
|
71
|
-
### Notifications
|
72
|
-
|
73
|
-
For notifications you will want to supply a #title and #body instance method,
|
74
|
-
and check to see if the #initialize and #full_notice methods in the
|
75
|
-
Bullet::Notification::Base class fit your needs.
|
data/Rakefile
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
2
|
-
require 'bundler'
|
3
|
-
Bundler.setup
|
4
|
-
|
5
|
-
require 'rake'
|
6
|
-
require 'rspec'
|
7
|
-
require 'rspec/core/rake_task'
|
8
|
-
|
9
|
-
require 'bullet/version'
|
10
|
-
|
11
|
-
task :build do
|
12
|
-
system 'gem build bullet.gemspec'
|
13
|
-
end
|
14
|
-
|
15
|
-
task install: :build do
|
16
|
-
system "sudo gem install bullet-#{Bullet::VERSION}.gem"
|
17
|
-
end
|
18
|
-
|
19
|
-
task release: :build do
|
20
|
-
puts "Tagging #{Bullet::VERSION}..."
|
21
|
-
system "git tag -a #{Bullet::VERSION} -m 'Tagging #{Bullet::VERSION}'"
|
22
|
-
puts 'Pushing to Github...'
|
23
|
-
system 'git push --tags'
|
24
|
-
puts 'Pushing to rubygems.org...'
|
25
|
-
system "gem push bullet-#{Bullet::VERSION}.gem"
|
26
|
-
end
|
27
|
-
|
28
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
-
end
|
31
|
-
|
32
|
-
RSpec::Core::RakeTask.new('spec:progress') do |spec|
|
33
|
-
spec.rspec_opts = %w[--format progress]
|
34
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
35
|
-
end
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'rdoc/task'
|
39
|
-
|
40
|
-
desc 'Generate documentation for the plugin.'
|
41
|
-
Rake::RDocTask.new do |rdoc|
|
42
|
-
rdoc.rdoc_dir = 'rdoc'
|
43
|
-
rdoc.title = "bullet #{Bullet::VERSION}"
|
44
|
-
rdoc.rdoc_files.include('README*')
|
45
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
-
end
|
47
|
-
rescue LoadError
|
48
|
-
puts 'RDocTask is not supported for this platform'
|
49
|
-
end
|
50
|
-
|
51
|
-
task default: :spec
|
data/bullet.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
require 'bullet/version'
|
7
|
-
|
8
|
-
Gem::Specification.new do |s|
|
9
|
-
s.name = 'bullet'
|
10
|
-
s.version = Bullet::VERSION
|
11
|
-
s.platform = Gem::Platform::RUBY
|
12
|
-
s.authors = ['Richard Huang']
|
13
|
-
s.email = ['flyerhzm@gmail.com']
|
14
|
-
s.homepage = 'https://github.com/flyerhzm/bullet'
|
15
|
-
s.summary = 'help to kill N+1 queries and unused eager loading.'
|
16
|
-
s.description = 'help to kill N+1 queries and unused eager loading.'
|
17
|
-
s.metadata = {
|
18
|
-
'changelog_uri' => 'https://github.com/flyerhzm/bullet/blob/master/CHANGELOG.md',
|
19
|
-
'source_code_uri' => 'https://github.com/flyerhzm/bullet'
|
20
|
-
}
|
21
|
-
|
22
|
-
s.license = 'MIT'
|
23
|
-
|
24
|
-
s.required_ruby_version = '>= 2.3'
|
25
|
-
s.required_rubygems_version = '>= 1.3.6'
|
26
|
-
|
27
|
-
s.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
28
|
-
s.add_runtime_dependency 'uniform_notifier', '~> 1.11'
|
29
|
-
|
30
|
-
s.files = `git ls-files`.split("\n")
|
31
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
32
|
-
s.require_paths = ['lib']
|
33
|
-
end
|
data/perf/benchmark.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH << 'lib'
|
4
|
-
require 'benchmark'
|
5
|
-
require 'rails'
|
6
|
-
require 'active_record'
|
7
|
-
require 'activerecord-import'
|
8
|
-
require 'bullet'
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'perftools'
|
12
|
-
rescue LoadError
|
13
|
-
puts "Could not load perftools.rb, profiling won't be possible"
|
14
|
-
end
|
15
|
-
|
16
|
-
class Post < ActiveRecord::Base
|
17
|
-
belongs_to :user
|
18
|
-
has_many :comments
|
19
|
-
end
|
20
|
-
|
21
|
-
class Comment < ActiveRecord::Base
|
22
|
-
belongs_to :user
|
23
|
-
belongs_to :post
|
24
|
-
end
|
25
|
-
|
26
|
-
class User < ActiveRecord::Base
|
27
|
-
has_many :posts
|
28
|
-
has_many :comments
|
29
|
-
end
|
30
|
-
|
31
|
-
# create database bullet_benchmark;
|
32
|
-
ActiveRecord::Base.establish_connection(
|
33
|
-
adapter: 'mysql2',
|
34
|
-
database: 'bullet_benchmark',
|
35
|
-
server: '/tmp/mysql.socket',
|
36
|
-
username: 'root'
|
37
|
-
)
|
38
|
-
|
39
|
-
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
|
40
|
-
|
41
|
-
ActiveRecord::Schema.define(version: 1) do
|
42
|
-
create_table :posts do |t|
|
43
|
-
t.column :title, :string
|
44
|
-
t.column :body, :string
|
45
|
-
t.column :user_id, :integer
|
46
|
-
end
|
47
|
-
|
48
|
-
create_table :comments do |t|
|
49
|
-
t.column :body, :string
|
50
|
-
t.column :post_id, :integer
|
51
|
-
t.column :user_id, :integer
|
52
|
-
end
|
53
|
-
|
54
|
-
create_table :users do |t|
|
55
|
-
t.column :name, :string
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
users_size = 100
|
60
|
-
posts_size = 1_000
|
61
|
-
comments_size = 10_000
|
62
|
-
users = []
|
63
|
-
users_size.times { |i| users << User.new(name: "user#{i}") }
|
64
|
-
User.import users
|
65
|
-
users = User.all
|
66
|
-
|
67
|
-
posts = []
|
68
|
-
posts_size.times { |i| posts << Post.new(title: "Title #{i}", body: "Body #{i}", user: users[i % 100]) }
|
69
|
-
Post.import posts
|
70
|
-
posts = Post.all
|
71
|
-
|
72
|
-
comments = []
|
73
|
-
comments_size.times { |i| comments << Comment.new(body: "Comment #{i}", post: posts[i % 1_000], user: users[i % 100]) }
|
74
|
-
Comment.import comments
|
75
|
-
|
76
|
-
puts 'Start benchmarking...'
|
77
|
-
|
78
|
-
Bullet.enable = true
|
79
|
-
|
80
|
-
Benchmark.bm(70) do |bm|
|
81
|
-
bm.report("Querying & Iterating #{posts_size} Posts with #{comments_size} Comments and #{users_size} Users") do
|
82
|
-
10.times do
|
83
|
-
Bullet.start_request
|
84
|
-
Post.select('SQL_NO_CACHE *').includes(:user, comments: :user).each do |p|
|
85
|
-
p.title
|
86
|
-
p.user.name
|
87
|
-
p.comments.each do |c|
|
88
|
-
c.body
|
89
|
-
c.user.name
|
90
|
-
end
|
91
|
-
end
|
92
|
-
Bullet.end_request
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
puts 'End benchmarking...'
|
98
|
-
|
99
|
-
# Run benchmark with bundler
|
100
|
-
#
|
101
|
-
# bundle exec ruby perf/benchmark.rb
|
102
|
-
#
|
103
|
-
# bullet 2.3.0 with rails 3.2.2
|
104
|
-
# user system total real
|
105
|
-
# Querying & Iterating 1000 Posts with 10000 Comments and 100 Users 16.460000 0.190000 16.650000 ( 16.968246)
|
106
|
-
#
|
107
|
-
# bullet 2.3.0 with rails 3.1.4
|
108
|
-
# user system total real
|
109
|
-
# Querying & Iterating 1000 Posts with 10000 Comments and 100 Users 14.600000 0.130000 14.730000 ( 14.937590)
|
110
|
-
#
|
111
|
-
# bullet 2.3.0 with rails 3.0.12
|
112
|
-
# user system total real
|
113
|
-
# Querying & Iterating 1000 Posts with 10000 Comments and 100 Users 26.120000 0.430000 26.550000 ( 27.179304)
|
114
|
-
#
|
115
|
-
#
|
116
|
-
# bullet 2.2.1 with rails 3.0.12
|
117
|
-
# user system total real
|
118
|
-
# Querying & Iterating 1000 Posts with 10000 Comments and 100 Users 29.970000 0.270000 30.240000 ( 30.452083)
|
data/rails/init.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Bullet
|
6
|
-
module Detector
|
7
|
-
describe Association do
|
8
|
-
before :all do
|
9
|
-
@post1 = Post.first
|
10
|
-
@post2 = Post.last
|
11
|
-
end
|
12
|
-
|
13
|
-
context '.add_object_association' do
|
14
|
-
it 'should add object, associations pair' do
|
15
|
-
Association.add_object_associations(@post1, :associations)
|
16
|
-
expect(Association.send(:object_associations)).to be_include(@post1.bullet_key, :associations)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context '.add_call_object_associations' do
|
21
|
-
it 'should add call object, associations pair' do
|
22
|
-
Association.add_call_object_associations(@post1, :associations)
|
23
|
-
expect(Association.send(:call_object_associations)).to be_include(@post1.bullet_key, :associations)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Bullet
|
6
|
-
module Detector
|
7
|
-
describe CounterCache do
|
8
|
-
before :all do
|
9
|
-
@post1 = Post.first
|
10
|
-
@post2 = Post.last
|
11
|
-
end
|
12
|
-
|
13
|
-
context '.add_counter_cache' do
|
14
|
-
it 'should create notification if conditions met' do
|
15
|
-
expect(CounterCache).to receive(:conditions_met?).with(@post1, %i[comments]).and_return(true)
|
16
|
-
expect(CounterCache).to receive(:create_notification).with('Post', %i[comments])
|
17
|
-
CounterCache.add_counter_cache(@post1, %i[comments])
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should not create notification if conditions not met' do
|
21
|
-
expect(CounterCache).to receive(:conditions_met?).with(@post1, %i[comments]).and_return(false)
|
22
|
-
expect(CounterCache).to receive(:create_notification).never
|
23
|
-
CounterCache.add_counter_cache(@post1, %i[comments])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context '.add_possible_objects' do
|
28
|
-
it 'should add possible objects' do
|
29
|
-
CounterCache.add_possible_objects([@post1, @post2])
|
30
|
-
expect(CounterCache.possible_objects).to be_include(@post1.bullet_key)
|
31
|
-
expect(CounterCache.possible_objects).to be_include(@post2.bullet_key)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should add impossible object' do
|
35
|
-
CounterCache.add_impossible_object(@post1)
|
36
|
-
expect(CounterCache.impossible_objects).to be_include(@post1.bullet_key)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context '.conditions_met?' do
|
41
|
-
it 'should be true when object is possible, not impossible' do
|
42
|
-
CounterCache.add_possible_objects(@post1)
|
43
|
-
expect(CounterCache.conditions_met?(@post1, :associations)).to eq true
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should be false when object is not possible' do
|
47
|
-
expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should be false when object is possible, and impossible' do
|
51
|
-
CounterCache.add_possible_objects(@post1)
|
52
|
-
CounterCache.add_impossible_object(@post1)
|
53
|
-
expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Bullet
|
6
|
-
module Detector
|
7
|
-
describe NPlusOneQuery do
|
8
|
-
before(:all) do
|
9
|
-
@post = Post.first
|
10
|
-
@post2 = Post.last
|
11
|
-
end
|
12
|
-
|
13
|
-
context '.call_association' do
|
14
|
-
it 'should add call_object_associations' do
|
15
|
-
expect(NPlusOneQuery).to receive(:add_call_object_associations).with(@post, :associations)
|
16
|
-
NPlusOneQuery.call_association(@post, :associations)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context '.possible?' do
|
21
|
-
it 'should be true if possible_objects contain' do
|
22
|
-
NPlusOneQuery.add_possible_objects(@post)
|
23
|
-
expect(NPlusOneQuery.possible?(@post)).to eq true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context '.impossible?' do
|
28
|
-
it 'should be true if impossible_objects contain' do
|
29
|
-
NPlusOneQuery.add_impossible_object(@post)
|
30
|
-
expect(NPlusOneQuery.impossible?(@post)).to eq true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context '.association?' do
|
35
|
-
it 'should be true if object, associations pair is already existed' do
|
36
|
-
NPlusOneQuery.add_object_associations(@post, :association)
|
37
|
-
expect(NPlusOneQuery.association?(@post, :association)).to eq true
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should be false if object, association pair is not existed' do
|
41
|
-
NPlusOneQuery.add_object_associations(@post, :association1)
|
42
|
-
expect(NPlusOneQuery.association?(@post, :association2)).to eq false
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context '.conditions_met?' do
|
47
|
-
it 'should be true if object is possible, not impossible and object, associations pair is not already existed' do
|
48
|
-
allow(NPlusOneQuery).to receive(:possible?).with(@post).and_return(true)
|
49
|
-
allow(NPlusOneQuery).to receive(:impossible?).with(@post).and_return(false)
|
50
|
-
allow(NPlusOneQuery).to receive(:association?).with(@post, :associations).and_return(false)
|
51
|
-
expect(NPlusOneQuery.conditions_met?(@post, :associations)).to eq true
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should be false if object is not possible, not impossible and object, associations pair is not already existed' do
|
55
|
-
allow(NPlusOneQuery).to receive(:possible?).with(@post).and_return(false)
|
56
|
-
allow(NPlusOneQuery).to receive(:impossible?).with(@post).and_return(false)
|
57
|
-
allow(NPlusOneQuery).to receive(:association?).with(@post, :associations).and_return(false)
|
58
|
-
expect(NPlusOneQuery.conditions_met?(@post, :associations)).to eq false
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should be false if object is possible, but impossible and object, associations pair is not already existed' do
|
62
|
-
allow(NPlusOneQuery).to receive(:possible?).with(@post).and_return(true)
|
63
|
-
allow(NPlusOneQuery).to receive(:impossible?).with(@post).and_return(true)
|
64
|
-
allow(NPlusOneQuery).to receive(:association?).with(@post, :associations).and_return(false)
|
65
|
-
expect(NPlusOneQuery.conditions_met?(@post, :associations)).to eq false
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should be false if object is possible, not impossible and object, associations pair is already existed' do
|
69
|
-
allow(NPlusOneQuery).to receive(:possible?).with(@post).and_return(true)
|
70
|
-
allow(NPlusOneQuery).to receive(:impossible?).with(@post).and_return(false)
|
71
|
-
allow(NPlusOneQuery).to receive(:association?).with(@post, :associations).and_return(true)
|
72
|
-
expect(NPlusOneQuery.conditions_met?(@post, :associations)).to eq false
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context '.call_association' do
|
77
|
-
it 'should create notification if conditions met' do
|
78
|
-
expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(true)
|
79
|
-
expect(NPlusOneQuery).to receive(:caller_in_project).and_return(%w[caller])
|
80
|
-
expect(NPlusOneQuery).to receive(:create_notification).with(%w[caller], 'Post', :association)
|
81
|
-
NPlusOneQuery.call_association(@post, :association)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should not create notification if conditions not met' do
|
85
|
-
expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(false)
|
86
|
-
expect(NPlusOneQuery).not_to receive(:caller_in_project!)
|
87
|
-
expect(NPlusOneQuery).not_to receive(:create_notification).with('Post', :association)
|
88
|
-
NPlusOneQuery.call_association(@post, :association)
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'stacktrace_excludes' do
|
92
|
-
before { Bullet.stacktrace_excludes = [/def/] }
|
93
|
-
after { Bullet.stacktrace_excludes = nil }
|
94
|
-
|
95
|
-
it 'should not create notification when stacktrace contains paths that are in the exclude list' do
|
96
|
-
in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
|
97
|
-
included_path = OpenStruct.new(absolute_path: '/ghi/ghi.rb')
|
98
|
-
excluded_path = OpenStruct.new(absolute_path: '/def/def.rb')
|
99
|
-
|
100
|
-
expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, included_path, excluded_path])
|
101
|
-
expect(NPlusOneQuery).to_not receive(:create_notification)
|
102
|
-
NPlusOneQuery.call_association(@post, :association)
|
103
|
-
end
|
104
|
-
|
105
|
-
# just a sanity spec to make sure the following spec works correctly
|
106
|
-
it "should create notification when stacktrace contains methods that aren't in the exclude list" do
|
107
|
-
method = NPlusOneQuery.method(:excluded_stacktrace_path?).source_location
|
108
|
-
in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
|
109
|
-
excluded_path = OpenStruct.new(absolute_path: method.first, lineno: method.last)
|
110
|
-
|
111
|
-
expect(NPlusOneQuery).to receive(:caller_locations).at_least(1).and_return([in_project, excluded_path])
|
112
|
-
expect(NPlusOneQuery).to receive(:conditions_met?).and_return(true)
|
113
|
-
expect(NPlusOneQuery).to receive(:create_notification)
|
114
|
-
NPlusOneQuery.call_association(@post, :association)
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'should not create notification when stacktrace contains methods that are in the exclude list' do
|
118
|
-
method = NPlusOneQuery.method(:excluded_stacktrace_path?).source_location
|
119
|
-
Bullet.stacktrace_excludes = [method]
|
120
|
-
in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
|
121
|
-
excluded_path = OpenStruct.new(absolute_path: method.first, lineno: method.last)
|
122
|
-
|
123
|
-
expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, excluded_path])
|
124
|
-
expect(NPlusOneQuery).to_not receive(:create_notification)
|
125
|
-
NPlusOneQuery.call_association(@post, :association)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context '.add_possible_objects' do
|
131
|
-
it 'should add possible objects' do
|
132
|
-
NPlusOneQuery.add_possible_objects([@post, @post2])
|
133
|
-
expect(NPlusOneQuery.possible_objects).to be_include(@post.bullet_key)
|
134
|
-
expect(NPlusOneQuery.possible_objects).to be_include(@post2.bullet_key)
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'should not raise error if object is nil' do
|
138
|
-
expect { NPlusOneQuery.add_possible_objects(nil) }.not_to raise_error
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context '.add_impossible_object' do
|
143
|
-
it 'should add impossible object' do
|
144
|
-
NPlusOneQuery.add_impossible_object(@post)
|
145
|
-
expect(NPlusOneQuery.impossible_objects).to be_include(@post.bullet_key)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|