bullet 5.2.1 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -2
- data/lib/bullet/active_record3.rb +19 -0
- data/lib/bullet/active_record3x.rb +19 -0
- data/lib/bullet/active_record4.rb +19 -0
- data/lib/bullet/active_record41.rb +19 -0
- data/lib/bullet/active_record42.rb +15 -0
- data/lib/bullet/active_record5.rb +3 -3
- data/lib/bullet/version.rb +1 -1
- data/spec/integration/active_record3/association_spec.rb +10 -0
- data/spec/integration/active_record4/association_spec.rb +10 -0
- data/spec/integration/active_record5/association_spec.rb +10 -0
- 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: ed73722e74144833068cf4572e3624687a9db64b
|
4
|
+
data.tar.gz: e882a8f5c7e4bfbe1d37254e1255ed79fc3f3948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a62b1a339dccad8b79e97971c8d7fc73f977eb9d0b1c19758f59259e85531116fb57a9ef51c90e013d6051a27616ec861380d0940f658102155a163f52eb1873
|
7
|
+
data.tar.gz: de637d2bb853c67a5e7f2b269f698b18b59a481f5988025407d094e0442df03de805bc3890945e49accba76d3ae3c7a62c4185a8fde8d584550eac251a281836
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
-
## 5.
|
3
|
+
## 5.3.0 (15/08/2016)
|
4
4
|
|
5
|
-
* Fix env REQUEST_URI
|
6
5
|
* Fix false alert on through association with join sql #301
|
7
6
|
* Fix association.target in through_association can be singular #302
|
7
|
+
* Support find_by_sql #303
|
8
|
+
* Fix env REQUEST_URI
|
8
9
|
|
9
10
|
## 5.2.0 (07/26/2016)
|
10
11
|
|
@@ -4,6 +4,25 @@ module Bullet
|
|
4
4
|
|
5
5
|
def self.enable
|
6
6
|
require 'active_record'
|
7
|
+
::ActiveRecord::Base.class_eval do
|
8
|
+
class <<self
|
9
|
+
alias_method :origin_find_by_sql, :find_by_sql
|
10
|
+
def find_by_sql(sql)
|
11
|
+
result = origin_find_by_sql(sql)
|
12
|
+
if Bullet.start?
|
13
|
+
if result.is_a? Array
|
14
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
15
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
16
|
+
elsif result.is_a? ::ActiveRecord::Base
|
17
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
18
|
+
Bullet::Detector::CounterCache.add_impossible_object(result)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
7
26
|
::ActiveRecord::Relation.class_eval do
|
8
27
|
alias_method :origin_to_a, :to_a
|
9
28
|
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
@@ -2,6 +2,25 @@ module Bullet
|
|
2
2
|
module ActiveRecord
|
3
3
|
def self.enable
|
4
4
|
require 'active_record'
|
5
|
+
::ActiveRecord::Base.class_eval do
|
6
|
+
class <<self
|
7
|
+
alias_method :origin_find_by_sql, :find_by_sql
|
8
|
+
def find_by_sql(sql, binds = [])
|
9
|
+
result = origin_find_by_sql(sql, binds)
|
10
|
+
if Bullet.start?
|
11
|
+
if result.is_a? Array
|
12
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
13
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
14
|
+
elsif result.is_a? ::ActiveRecord::Base
|
15
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
16
|
+
Bullet::Detector::CounterCache.add_impossible_object(result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
::ActiveRecord::Relation.class_eval do
|
6
25
|
alias_method :origin_to_a, :to_a
|
7
26
|
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
@@ -2,6 +2,25 @@ module Bullet
|
|
2
2
|
module ActiveRecord
|
3
3
|
def self.enable
|
4
4
|
require 'active_record'
|
5
|
+
::ActiveRecord::Base.class_eval do
|
6
|
+
class <<self
|
7
|
+
alias_method :origin_find_by_sql, :find_by_sql
|
8
|
+
def find_by_sql(sql, binds = [])
|
9
|
+
result = origin_find_by_sql(sql, binds)
|
10
|
+
if Bullet.start?
|
11
|
+
if result.is_a? Array
|
12
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
13
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
14
|
+
elsif result.is_a? ::ActiveRecord::Base
|
15
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
16
|
+
Bullet::Detector::CounterCache.add_impossible_object(result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
::ActiveRecord::Relation.class_eval do
|
6
25
|
alias_method :origin_to_a, :to_a
|
7
26
|
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
@@ -2,6 +2,25 @@ module Bullet
|
|
2
2
|
module ActiveRecord
|
3
3
|
def self.enable
|
4
4
|
require 'active_record'
|
5
|
+
::ActiveRecord::Base.class_eval do
|
6
|
+
class <<self
|
7
|
+
alias_method :origin_find_by_sql, :find_by_sql
|
8
|
+
def find_by_sql(sql, binds = [])
|
9
|
+
result = origin_find_by_sql(sql, binds)
|
10
|
+
if Bullet.start?
|
11
|
+
if result.is_a? Array
|
12
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
13
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
14
|
+
elsif result.is_a? ::ActiveRecord::Base
|
15
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
16
|
+
Bullet::Detector::CounterCache.add_impossible_object(result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
::ActiveRecord::Relation.class_eval do
|
6
25
|
alias_method :origin_to_a, :to_a
|
7
26
|
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
@@ -18,6 +18,21 @@ module Bullet
|
|
18
18
|
end
|
19
19
|
result
|
20
20
|
end
|
21
|
+
|
22
|
+
alias_method :origin_find_by_sql, :find_by_sql
|
23
|
+
def find_by_sql(sql, binds = [])
|
24
|
+
result = origin_find_by_sql(sql, binds)
|
25
|
+
if Bullet.start?
|
26
|
+
if result.is_a? Array
|
27
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
28
|
+
Bullet::Detector::CounterCache.add_possible_objects(result)
|
29
|
+
elsif result.is_a? ::ActiveRecord::Base
|
30
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
|
31
|
+
Bullet::Detector::CounterCache.add_impossible_object(result)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
result
|
35
|
+
end
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
@@ -20,9 +20,9 @@ module Bullet
|
|
20
20
|
require 'active_record'
|
21
21
|
::ActiveRecord::Base.class_eval do
|
22
22
|
class <<self
|
23
|
-
alias_method :
|
24
|
-
def
|
25
|
-
result =
|
23
|
+
alias_method :origin_find_by_sql, :find_by_sql
|
24
|
+
def find_by_sql(sql, binds = [], preparable: nil)
|
25
|
+
result = origin_find_by_sql(sql, binds, preparable: nil)
|
26
26
|
if Bullet.start?
|
27
27
|
if result.is_a? Array
|
28
28
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
data/lib/bullet/version.rb
CHANGED
@@ -13,6 +13,16 @@ if !mongoid? && active_record3?
|
|
13
13
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should detect non preload post => comments for find_by_sql" do
|
17
|
+
Post.find_by_sql("SELECT * FROM posts").each do |post|
|
18
|
+
post.comments.map(&:name)
|
19
|
+
end
|
20
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
21
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
22
|
+
|
23
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
24
|
+
end
|
25
|
+
|
16
26
|
it "should detect preload with post => comments" do
|
17
27
|
Post.includes(:comments).each do |post|
|
18
28
|
post.comments.map(&:name)
|
@@ -13,6 +13,16 @@ if !mongoid? && active_record4?
|
|
13
13
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should detect non preload post => comments for find_by_sql" do
|
17
|
+
Post.find_by_sql("SELECT * FROM posts").each do |post|
|
18
|
+
post.comments.map(&:name)
|
19
|
+
end
|
20
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
21
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
22
|
+
|
23
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
24
|
+
end
|
25
|
+
|
16
26
|
it "should detect preload with post => comments" do
|
17
27
|
Post.includes(:comments).each do |post|
|
18
28
|
post.comments.map(&:name)
|
@@ -13,6 +13,16 @@ if !mongoid? && active_record5?
|
|
13
13
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should detect non preload post => comments for find_by_sql" do
|
17
|
+
Post.find_by_sql("SELECT * FROM posts").each do |post|
|
18
|
+
post.comments.map(&:name)
|
19
|
+
end
|
20
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
21
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
22
|
+
|
23
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
24
|
+
end
|
25
|
+
|
16
26
|
it "should detect preload with post => comments" do
|
17
27
|
Post.includes(:comments).each do |post|
|
18
28
|
post.comments.map(&:name)
|
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.3.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-08-
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|