bullet 5.2.1 → 5.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c06cf9b6f47c5e634fc97060ca54c2921435d2d
4
- data.tar.gz: ad3f7ac0141cf94446805db9495c06db19bf5073
3
+ metadata.gz: ed73722e74144833068cf4572e3624687a9db64b
4
+ data.tar.gz: e882a8f5c7e4bfbe1d37254e1255ed79fc3f3948
5
5
  SHA512:
6
- metadata.gz: 323e475243dc0416bc4d0e5c884642685e05d54ed7681de6406a168326846e4e5b220c53ea41b1bcb814ca5159f1d22a75e54baba4e51877cea631f47e8e4398
7
- data.tar.gz: b84c10f9be778b1db9577857c39261669fd64889190b2aecaee5dbaf80b07542c75a3a1b976c5b132075875a008338d744ad370437ffdecbc0246b0a802026f1
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.2.1
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 :origin_find, :find
24
- def find(*args)
25
- result = origin_find(*args)
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)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "5.2.1"
3
+ VERSION = "5.3.0"
4
4
  end
@@ -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.2.1
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-12 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport