Class: Bullet::Detector::Association

Inherits:
Base
  • Object
show all
Defined in:
lib/bullet/detector/association.rb

Direct Known Subclasses

NPlusOneQuery, UnusedEagerAssociation

Class Method Summary collapse

Methods inherited from Base

end_request

Class Method Details

.add_call_object_associations(object, associations) ⇒ Object



27
28
29
# File 'lib/bullet/detector/association.rb', line 27

def add_call_object_associations(object, associations)
  call_object_associations.add( object, associations )
end

.add_eager_loadings(objects, associations) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bullet/detector/association.rb', line 39

def add_eager_loadings(objects, associations)
  objects = Array(objects)

  eager_loadings.each do |k, v|
    key_objects_overlap = k & objects

    next if key_objects_overlap.empty?

    if key_objects_overlap == k
      eager_loadings.add k, associations
      break

    else
      eager_loadings.merge key_objects_overlap, ( eager_loadings[k].dup  << associations )

      keys_without_objects = k - objects
      eager_loadings.merge keys_without_objects, eager_loadings[k] unless keys_without_objects.empty?

      eager_loadings.delete(k)
      objects = objects - k
    end
  end

  eager_loadings.add objects, associations unless objects.empty?
end

.add_impossible_object(object) ⇒ Object



35
36
37
# File 'lib/bullet/detector/association.rb', line 35

def add_impossible_object(object)
  impossible_objects.add object
end

.add_object_associations(object, associations) ⇒ Object



23
24
25
# File 'lib/bullet/detector/association.rb', line 23

def add_object_associations(object, associations)
  object_associations.add( object, associations )
end

.add_possible_objects(objects) ⇒ Object



31
32
33
# File 'lib/bullet/detector/association.rb', line 31

def add_possible_objects(objects)
  possible_objects.add objects
end

.clearObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bullet/detector/association.rb', line 9

def clear
  # Note that under ruby class variables are shared among the class
  # that declares them and all classes derived from that class.
  # The following variables are accessible by all classes that
  # derive from Bullet::Detector::Association - changing the variable
  # in one subclass will make the change visible to all subclasses!
  @@object_associations = nil
  @@callers = nil
  @@possible_objects = nil
  @@impossible_objects = nil
  @@call_object_associations = nil
  @@eager_loadings = nil
end

.start_requestObject



5
6
7
# File 'lib/bullet/detector/association.rb', line 5

def start_request
  @@checked = false
end