bullet 5.4.2 → 5.5.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.
@@ -1,56 +0,0 @@
1
- module Bullet
2
- module Mongoid
3
- def self.enable
4
- require 'mongoid'
5
-
6
- ::Mongoid::Contexts::Mongo.class_eval do
7
- alias_method :origin_first, :first
8
- alias_method :origin_last, :last
9
- alias_method :origin_iterate, :iterate
10
- alias_method :origin_eager_load, :eager_load
11
-
12
- def first
13
- result = origin_first
14
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
15
- result
16
- end
17
-
18
- def last
19
- result = origin_last
20
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
21
- result
22
- end
23
-
24
- def iterate(&block)
25
- records = execute.to_a
26
- if records.size > 1
27
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
28
- elsif records.size == 1
29
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
30
- end
31
- origin_iterate(&block)
32
- end
33
-
34
- def eager_load(docs)
35
- associations = criteria.inclusions.map(&:name)
36
- docs.each do |doc|
37
- Bullet::Detector::Association.add_object_associations(doc, associations)
38
- end
39
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
40
- origin_eager_load(docs)
41
- end
42
- end
43
-
44
- ::Mongoid::Relations::Accessors.class_eval do
45
- alias_method :origin_set_relation, :set_relation
46
-
47
- def set_relation(name, relation)
48
- if relation && relation.metadata.macro !~ /embed/
49
- Bullet::Detector::NPlusOneQuery.call_association(self, name)
50
- end
51
- origin_set_relation(name, relation)
52
- end
53
- end
54
- end
55
- end
56
- end