bullet_instructure 4.0.3 → 4.0.5

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: 62eede05f800964904846c200e404f63f24a9da0
4
- data.tar.gz: f2268ef8dac7c086cabe7dd6676494602a24ea00
3
+ metadata.gz: 98a4fd498802478eaf995e91645dcd5fa4722103
4
+ data.tar.gz: 2c74f0ebd2ab028a4e0f9ae3a1a1eac4e45ff849
5
5
  SHA512:
6
- metadata.gz: 9ecb2db6d652bff96daf3c96f8e57df76cc5a33cfeededdcb2cdfe474ab987976bebc4a1745faf0aece898246e390a4df7953ac0e32b89a42ba9b6a41692daef
7
- data.tar.gz: 786eed0ed7b673257f3afbf0fe3c31d63149dc63c345449ebbf0249712b111c554747431a293bb8a3a8fdf3b85af2ffc7d31e0d15114211820814bb0754e626e
6
+ metadata.gz: f0b57d0a603bab53bdbe33f40afa8d8e30694200827f5cbebbc05cfed147e180823200278852171e5a6b7fcfe6b61e24d63cf7221dc93548501c790c462b3d4b
7
+ data.tar.gz: fcf37e95d84a32a773cbb7dd2685819f95990ed29767825c162d48527154a349119b085a66551c1321f43ff6d7a199e6ededb2072b92bb75f4999699924a269a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p247
1
+ 2.1.5
@@ -8,30 +8,29 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  records = origin_to_a
11
- if records.first.class.name !~ /^HABTM_/
12
- if records.size > 1
13
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
14
- Bullet::Detector::CounterCache.add_possible_objects(records)
15
- elsif records.size == 1
16
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
17
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
18
- end
11
+ if records.size > 1
12
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
13
+ Bullet::Detector::CounterCache.add_possible_objects(records)
14
+ elsif records.size == 1
15
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
16
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
19
17
  end
20
18
  records
21
19
  end
22
20
  end
23
21
 
24
22
  ::ActiveRecord::Associations::Preloader.class_eval do
25
- alias_method :origin_preloaders_on, :preloaders_on
26
-
27
- def preloaders_on(association, records, scope)
28
- if records.first.class.name !~ /^HABTM_/
29
- records.each do |record|
30
- Bullet::Detector::Association.add_object_associations(record, association)
31
- end
32
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
23
+ # include query for one to many associations.
24
+ # keep this eager loadings.
25
+ alias_method :origin_initialize, :initialize
26
+ def initialize
27
+ origin_initialize
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)
33
32
  end
34
- origin_preloaders_on(association, records, scope)
33
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
35
34
  end
36
35
  end
37
36
 
@@ -39,43 +38,29 @@ module Bullet
39
38
  # add includes in scope
40
39
  alias_method :origin_find_with_associations, :find_with_associations
41
40
  def find_with_associations
42
- records = origin_find_with_associations
43
- associations = (eager_load_values + includes_values).uniq
44
- records.each do |record|
45
- Bullet::Detector::Association.add_object_associations(record, associations)
41
+ if block_given?
42
+ origin_find_with_associations { |r| yield r }
43
+ else
44
+ records = origin_find_with_associations
45
+ associations = (eager_load_values + includes_values).uniq
46
+ records.each do |record|
47
+ Bullet::Detector::Association.add_object_associations(record, associations)
48
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
49
+ end
50
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
51
+ records
46
52
  end
47
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
48
- records
49
53
  end
50
54
  end
51
55
 
52
56
  ::ActiveRecord::Associations::JoinDependency.class_eval do
53
- alias_method :origin_instantiate, :instantiate
54
57
  alias_method :origin_construct_model, :construct_model
55
-
56
- def instantiate(result_set, aliases)
57
- @bullet_eager_loadings = {}
58
- records = origin_instantiate(result_set, aliases)
59
-
60
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
61
- objects = eager_loadings_hash.keys
62
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
63
- end
64
- records
65
- end
66
-
67
58
  # call join associations
68
- def construct_model(record, node, row, model_cache, id, aliases)
69
- result = origin_construct_model(record, node, row, model_cache, id, aliases)
70
-
71
- associations = node.reflection.name
59
+ def construct_model(record, join, row)
60
+ associations = join.reflection.name
72
61
  Bullet::Detector::Association.add_object_associations(record, associations)
73
62
  Bullet::Detector::NPlusOneQuery.call_association(record, associations)
74
- @bullet_eager_loadings[record.class] ||= {}
75
- @bullet_eager_loadings[record.class][record] ||= Set.new
76
- @bullet_eager_loadings[record.class][record] << associations
77
-
78
- result
63
+ origin_construct_model(record, join, row)
79
64
  end
80
65
  end
81
66
 
@@ -83,14 +68,8 @@ module Bullet
83
68
  # call one to many associations
84
69
  alias_method :origin_load_target, :load_target
85
70
  def load_target
86
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
87
- origin_load_target
88
- end
89
-
90
- alias_method :origin_empty?, :empty?
91
- def empty?
92
71
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
93
- origin_empty?
72
+ origin_load_target
94
73
  end
95
74
  end
96
75
 
@@ -99,18 +78,26 @@ module Bullet
99
78
  alias_method :origin_reader, :reader
100
79
  def reader(force_reload = false)
101
80
  result = origin_reader(force_reload)
102
- if @owner.class.name !~ /^HABTM_/
103
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
104
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
105
- end
81
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
82
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
106
83
  result
107
84
  end
108
85
  end
109
86
 
87
+ ::ActiveRecord::Associations::Association.class_eval do
88
+ alias_method :origin_set_inverse_instance, :set_inverse_instance
89
+ def set_inverse_instance(record)
90
+ if record && invertible_for?(record)
91
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(record)
92
+ end
93
+ origin_set_inverse_instance(record)
94
+ end
95
+ end
96
+
110
97
  ::ActiveRecord::Associations::HasManyAssociation.class_eval do
111
98
  alias_method :origin_has_cached_counter?, :has_cached_counter?
112
99
 
113
- def has_cached_counter?(reflection = reflection())
100
+ def has_cached_counter?(reflection = reflection)
114
101
  result = origin_has_cached_counter?(reflection)
115
102
  Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
116
103
  result
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.0.3"
3
+ VERSION = "4.0.5"
4
4
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_instructure
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: uniform_notifier
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.6.0
41
41
  description: help to kill N+1 queries and unused eager loading, pretty formatter for
@@ -46,10 +46,10 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
50
- - .rspec
51
- - .ruby-version
52
- - .travis.yml
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".ruby-version"
52
+ - ".travis.yml"
53
53
  - CHANGELOG.md
54
54
  - Gemfile
55
55
  - Gemfile.mongoid
@@ -172,17 +172,17 @@ require_paths:
172
172
  - lib
173
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - '>='
175
+ - - ">="
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - '>='
180
+ - - ">="
181
181
  - !ruby/object:Gem::Version
182
182
  version: 1.3.6
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.0.3
185
+ rubygems_version: 2.4.6
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: help to kill N+1 queries and unused eager loading, pretty formatter for Instructure.
@@ -244,3 +244,4 @@ test_files:
244
244
  - spec/support/mongo_seed.rb
245
245
  - spec/support/rack_double.rb
246
246
  - spec/support/sqlite_seed.rb
247
+ has_rdoc: