diff --git a/lib/bullet/detector/unused_eager_association.rb b/lib/bullet/detector/unused_eager_association.rb index 26b656b9..2d0db37b 100644 --- a/lib/bullet/detector/unused_eager_association.rb +++ b/lib/bullet/detector/unused_eager_association.rb @@ -23,11 +23,13 @@ def self.create_notification(klazz, associations) end def self.call_object_association( object, association ) - eager_loadings.similarly_associated( object, association ). - collect { |related_object| call_object_associations[related_object] }. - compact. - flatten. - uniq + all = Set.new + eager_loadings.similarly_associated( object, association ).each do |related_object| + coa = call_object_associations[related_object] + next if coa.nil? + all.merge coa + end + all.to_a end def self.diff_object_association( object, association ) diff --git a/lib/bullet/registry/base.rb b/lib/bullet/registry/base.rb index 025a831a..2ad9fab3 100644 --- a/lib/bullet/registry/base.rb +++ b/lib/bullet/registry/base.rb @@ -24,19 +24,14 @@ def select( *args, &block ) end def add( key, value ) - @registry[key] ||= [] + @registry[key] ||= Set.new if value.is_a? Array @registry[key] += value else @registry[key] << value end - unique( @registry[key] ) end - private - def unique( array ) - array.uniq! - end end end end