bullet 6.0.2 → 6.1.4
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 +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +25 -0
- data/Gemfile.rails-6.0 +1 -1
- data/Gemfile.rails-6.1 +15 -0
- data/README.md +12 -2
- data/lib/bullet.rb +31 -20
- data/lib/bullet/active_job.rb +1 -3
- data/lib/bullet/active_record4.rb +9 -23
- data/lib/bullet/active_record41.rb +7 -19
- data/lib/bullet/active_record42.rb +8 -16
- data/lib/bullet/active_record5.rb +188 -170
- data/lib/bullet/active_record52.rb +187 -161
- data/lib/bullet/active_record60.rb +194 -175
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +17 -23
- data/lib/bullet/dependency.rb +42 -34
- data/lib/bullet/detector/association.rb +24 -18
- data/lib/bullet/detector/base.rb +1 -2
- data/lib/bullet/detector/counter_cache.rb +10 -6
- data/lib/bullet/detector/n_plus_one_query.rb +18 -8
- data/lib/bullet/detector/unused_eager_loading.rb +5 -2
- data/lib/bullet/mongoid4x.rb +3 -7
- data/lib/bullet/mongoid5x.rb +3 -7
- data/lib/bullet/mongoid6x.rb +3 -7
- data/lib/bullet/mongoid7x.rb +3 -7
- data/lib/bullet/notification/base.rb +14 -18
- data/lib/bullet/notification/n_plus_one_query.rb +2 -4
- data/lib/bullet/notification/unused_eager_loading.rb +2 -4
- data/lib/bullet/rack.rb +23 -15
- data/lib/bullet/stack_trace_filter.rb +7 -16
- data/lib/bullet/version.rb +1 -1
- data/lib/generators/bullet/install_generator.rb +23 -23
- data/perf/benchmark.rb +8 -14
- data/spec/bullet/detector/counter_cache_spec.rb +6 -6
- data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
- data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -6
- data/spec/bullet/notification/base_spec.rb +1 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +16 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
- data/spec/bullet/rack_spec.rb +133 -7
- data/spec/bullet/registry/association_spec.rb +2 -2
- data/spec/bullet/registry/base_spec.rb +1 -1
- data/spec/bullet_spec.rb +10 -29
- data/spec/integration/active_record/association_spec.rb +77 -122
- data/spec/integration/counter_cache_spec.rb +10 -30
- data/spec/integration/mongoid/association_spec.rb +18 -32
- data/spec/models/attachment.rb +5 -0
- data/spec/models/folder.rb +1 -2
- data/spec/models/group.rb +1 -2
- data/spec/models/page.rb +1 -2
- data/spec/models/submission.rb +1 -0
- data/spec/models/user.rb +1 -0
- data/spec/models/writer.rb +1 -2
- data/spec/spec_helper.rb +6 -10
- data/spec/support/bullet_ext.rb +8 -9
- data/spec/support/mongo_seed.rb +2 -16
- data/spec/support/sqlite_seed.rb +8 -0
- metadata +10 -6
    
        data/lib/bullet/bullet_xhr.js
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            (function() {
         | 
| 1 | 
            +
            (function () {
         | 
| 2 2 | 
             
              var oldOpen = window.XMLHttpRequest.prototype.open;
         | 
| 3 3 | 
             
              var oldSend = window.XMLHttpRequest.prototype.send;
         | 
| 4 4 |  | 
| @@ -10,47 +10,41 @@ | |
| 10 10 | 
             
              if (isBulletInitiated()) return;
         | 
| 11 11 |  | 
| 12 12 | 
             
              function isBulletInitiated() {
         | 
| 13 | 
            -
                return oldOpen.name ==  | 
| 13 | 
            +
                return oldOpen.name == "bulletXHROpen" && oldSend.name == "bulletXHRSend";
         | 
| 14 14 | 
             
              }
         | 
| 15 15 | 
             
              function bulletXHROpen(_, url) {
         | 
| 16 16 | 
             
                this._storedUrl = url;
         | 
| 17 | 
            -
                return  | 
| 17 | 
            +
                return Reflect.apply(oldOpen, this, arguments);
         | 
| 18 18 | 
             
              }
         | 
| 19 19 | 
             
              function bulletXHRSend() {
         | 
| 20 20 | 
             
                if (this.onload) {
         | 
| 21 21 | 
             
                  this._storedOnload = this.onload;
         | 
| 22 22 | 
             
                }
         | 
| 23 | 
            -
                this.addEventListener( | 
| 24 | 
            -
                return  | 
| 23 | 
            +
                this.addEventListener("load", bulletXHROnload);
         | 
| 24 | 
            +
                return Reflect.apply(oldSend, this, arguments);
         | 
| 25 25 | 
             
              }
         | 
| 26 26 | 
             
              function bulletXHROnload() {
         | 
| 27 27 | 
             
                if (
         | 
| 28 | 
            -
                  this._storedUrl.startsWith(
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  ) ||
         | 
| 31 | 
            -
                  !this._storedUrl.startsWith('http') // For relative paths
         | 
| 28 | 
            +
                  this._storedUrl.startsWith(window.location.protocol + "//" + window.location.host) ||
         | 
| 29 | 
            +
                  !this._storedUrl.startsWith("http") // For relative paths
         | 
| 32 30 | 
             
                ) {
         | 
| 33 | 
            -
                  var bulletFooterText = this.getResponseHeader( | 
| 31 | 
            +
                  var bulletFooterText = this.getResponseHeader("X-bullet-footer-text");
         | 
| 34 32 | 
             
                  if (bulletFooterText) {
         | 
| 35 | 
            -
                    setTimeout(()  | 
| 36 | 
            -
                      var oldHtml = document
         | 
| 37 | 
            -
                        .getElementById('bullet-footer')
         | 
| 38 | 
            -
                        .innerHTML.split('<br>');
         | 
| 33 | 
            +
                    setTimeout(function() {
         | 
| 34 | 
            +
                      var oldHtml = document.querySelector("#bullet-footer").innerHTML.split("<br>");
         | 
| 39 35 | 
             
                      var header = oldHtml[0];
         | 
| 40 36 | 
             
                      oldHtml = oldHtml.slice(1, oldHtml.length);
         | 
| 41 37 | 
             
                      var newHtml = oldHtml.concat(JSON.parse(bulletFooterText));
         | 
| 42 38 | 
             
                      newHtml = newHtml.slice(newHtml.length - 10, newHtml.length); // rotate through 10 most recent
         | 
| 43 | 
            -
                      document. | 
| 44 | 
            -
                        'bullet-footer'
         | 
| 45 | 
            -
                      ).innerHTML = `${header}<br>${newHtml.join('<br>')}`;
         | 
| 39 | 
            +
                      document.querySelector("#bullet-footer").innerHTML = `${header}<br>${newHtml.join("<br>")}`;
         | 
| 46 40 | 
             
                    }, 0);
         | 
| 47 41 | 
             
                  }
         | 
| 48 | 
            -
                  var bulletConsoleText = this.getResponseHeader( | 
| 49 | 
            -
                  if (bulletConsoleText && typeof console !==  | 
| 50 | 
            -
                    setTimeout(()  | 
| 51 | 
            -
                      JSON.parse(bulletConsoleText).forEach(message => {
         | 
| 42 | 
            +
                  var bulletConsoleText = this.getResponseHeader("X-bullet-console-text");
         | 
| 43 | 
            +
                  if (bulletConsoleText && typeof console !== "undefined" && console.log) {
         | 
| 44 | 
            +
                    setTimeout(function() {
         | 
| 45 | 
            +
                      JSON.parse(bulletConsoleText).forEach((message) => {
         | 
| 52 46 | 
             
                        if (console.groupCollapsed && console.groupEnd) {
         | 
| 53 | 
            -
                          console.groupCollapsed( | 
| 47 | 
            +
                          console.groupCollapsed("Uniform Notifier");
         | 
| 54 48 | 
             
                          console.log(message);
         | 
| 55 49 | 
             
                          console.groupEnd();
         | 
| 56 50 | 
             
                        } else {
         | 
| @@ -61,7 +55,7 @@ | |
| 61 55 | 
             
                  }
         | 
| 62 56 | 
             
                }
         | 
| 63 57 | 
             
                if (this._storedOnload) {
         | 
| 64 | 
            -
                  return  | 
| 58 | 
            +
                  return Reflect.apply(this._storedOnload, this, arguments);
         | 
| 65 59 | 
             
                }
         | 
| 66 60 | 
             
              }
         | 
| 67 61 | 
             
              window.XMLHttpRequest.prototype.open = bulletXHROpen;
         | 
    
        data/lib/bullet/dependency.rb
    CHANGED
    
    | @@ -3,49 +3,53 @@ | |
| 3 3 | 
             
            module Bullet
         | 
| 4 4 | 
             
              module Dependency
         | 
| 5 5 | 
             
                def mongoid?
         | 
| 6 | 
            -
                  @mongoid ||= defined? | 
| 6 | 
            +
                  @mongoid ||= defined?(::Mongoid)
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 9 | 
             
                def active_record?
         | 
| 10 | 
            -
                  @active_record ||= defined? | 
| 10 | 
            +
                  @active_record ||= defined?(::ActiveRecord)
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                def active_record_version
         | 
| 14 | 
            -
                  @active_record_version ||= | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 14 | 
            +
                  @active_record_version ||=
         | 
| 15 | 
            +
                    begin
         | 
| 16 | 
            +
                      if active_record40?
         | 
| 17 | 
            +
                        'active_record4'
         | 
| 18 | 
            +
                      elsif active_record41?
         | 
| 19 | 
            +
                        'active_record41'
         | 
| 20 | 
            +
                      elsif active_record42?
         | 
| 21 | 
            +
                        'active_record42'
         | 
| 22 | 
            +
                      elsif active_record50?
         | 
| 23 | 
            +
                        'active_record5'
         | 
| 24 | 
            +
                      elsif active_record51?
         | 
| 25 | 
            +
                        'active_record5'
         | 
| 26 | 
            +
                      elsif active_record52?
         | 
| 27 | 
            +
                        'active_record52'
         | 
| 28 | 
            +
                      elsif active_record60?
         | 
| 29 | 
            +
                        'active_record60'
         | 
| 30 | 
            +
                      elsif active_record61?
         | 
| 31 | 
            +
                        'active_record61'
         | 
| 32 | 
            +
                      else
         | 
| 33 | 
            +
                        raise "Bullet does not support active_record #{::ActiveRecord::VERSION::STRING} yet"
         | 
| 34 | 
            +
                      end
         | 
| 35 | 
            +
                    end
         | 
| 33 36 | 
             
                end
         | 
| 34 37 |  | 
| 35 38 | 
             
                def mongoid_version
         | 
| 36 | 
            -
                  @mongoid_version ||= | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 39 | 
            +
                  @mongoid_version ||=
         | 
| 40 | 
            +
                    begin
         | 
| 41 | 
            +
                      if mongoid4x?
         | 
| 42 | 
            +
                        'mongoid4x'
         | 
| 43 | 
            +
                      elsif mongoid5x?
         | 
| 44 | 
            +
                        'mongoid5x'
         | 
| 45 | 
            +
                      elsif mongoid6x?
         | 
| 46 | 
            +
                        'mongoid6x'
         | 
| 47 | 
            +
                      elsif mongoid7x?
         | 
| 48 | 
            +
                        'mongoid7x'
         | 
| 49 | 
            +
                      else
         | 
| 50 | 
            +
                        raise "Bullet does not support mongoid #{::Mongoid::VERSION} yet"
         | 
| 51 | 
            +
                      end
         | 
| 52 | 
            +
                    end
         | 
| 49 53 | 
             
                end
         | 
| 50 54 |  | 
| 51 55 | 
             
                def active_record4?
         | 
| @@ -88,6 +92,10 @@ module Bullet | |
| 88 92 | 
             
                  active_record6? && ::ActiveRecord::VERSION::MINOR == 0
         | 
| 89 93 | 
             
                end
         | 
| 90 94 |  | 
| 95 | 
            +
                def active_record61?
         | 
| 96 | 
            +
                  active_record6? && ::ActiveRecord::VERSION::MINOR == 1
         | 
| 97 | 
            +
                end
         | 
| 98 | 
            +
             | 
| 91 99 | 
             
                def mongoid4x?
         | 
| 92 100 | 
             
                  mongoid? && ::Mongoid::VERSION =~ /\A4/
         | 
| 93 101 | 
             
                end
         | 
| @@ -3,13 +3,16 @@ | |
| 3 3 | 
             
            module Bullet
         | 
| 4 4 | 
             
              module Detector
         | 
| 5 5 | 
             
                class Association < Base
         | 
| 6 | 
            -
                  class <<self
         | 
| 6 | 
            +
                  class << self
         | 
| 7 7 | 
             
                    def add_object_associations(object, associations)
         | 
| 8 8 | 
             
                      return unless Bullet.start?
         | 
| 9 9 | 
             
                      return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
         | 
| 10 10 | 
             
                      return unless object.bullet_primary_key_value
         | 
| 11 11 |  | 
| 12 | 
            -
                      Bullet.debug( | 
| 12 | 
            +
                      Bullet.debug(
         | 
| 13 | 
            +
                        'Detector::Association#add_object_associations',
         | 
| 14 | 
            +
                        "object: #{object.bullet_key}, associations: #{associations}"
         | 
| 15 | 
            +
                      )
         | 
| 13 16 | 
             
                      object_associations.add(object.bullet_key, associations)
         | 
| 14 17 | 
             
                    end
         | 
| 15 18 |  | 
| @@ -18,7 +21,10 @@ module Bullet | |
| 18 21 | 
             
                      return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
         | 
| 19 22 | 
             
                      return unless object.bullet_primary_key_value
         | 
| 20 23 |  | 
| 21 | 
            -
                      Bullet.debug( | 
| 24 | 
            +
                      Bullet.debug(
         | 
| 25 | 
            +
                        'Detector::Association#add_call_object_associations',
         | 
| 26 | 
            +
                        "object: #{object.bullet_key}, associations: #{associations}"
         | 
| 27 | 
            +
                      )
         | 
| 22 28 | 
             
                      call_object_associations.add(object.bullet_key, associations)
         | 
| 23 29 | 
             
                    end
         | 
| 24 30 |  | 
| @@ -40,33 +46,33 @@ module Bullet | |
| 40 46 |  | 
| 41 47 | 
             
                    private
         | 
| 42 48 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 49 | 
            +
                    # object_associations keep the object relationships
         | 
| 50 | 
            +
                    # that the object has many associations.
         | 
| 51 | 
            +
                    # e.g. { "Post:1" => [:comments] }
         | 
| 52 | 
            +
                    # the object_associations keep all associations that may be or may no be
         | 
| 53 | 
            +
                    # unpreload associations or unused preload associations.
         | 
| 48 54 | 
             
                    def object_associations
         | 
| 49 55 | 
             
                      Thread.current[:bullet_object_associations]
         | 
| 50 56 | 
             
                    end
         | 
| 51 57 |  | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 58 | 
            +
                    # call_object_associations keep the object relationships
         | 
| 59 | 
            +
                    # that object.associations is called.
         | 
| 60 | 
            +
                    # e.g. { "Post:1" => [:comments] }
         | 
| 61 | 
            +
                    # they are used to detect unused preload associations.
         | 
| 56 62 | 
             
                    def call_object_associations
         | 
| 57 63 | 
             
                      Thread.current[:bullet_call_object_associations]
         | 
| 58 64 | 
             
                    end
         | 
| 59 65 |  | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 66 | 
            +
                    # inversed_objects keeps object relationships
         | 
| 67 | 
            +
                    # that association is inversed.
         | 
| 68 | 
            +
                    # e.g. { "Comment:1" => ["post"] }
         | 
| 63 69 | 
             
                    def inversed_objects
         | 
| 64 70 | 
             
                      Thread.current[:bullet_inversed_objects]
         | 
| 65 71 | 
             
                    end
         | 
| 66 72 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 73 | 
            +
                    # eager_loadings keep the object relationships
         | 
| 74 | 
            +
                    # that the associations are preloaded by find :include.
         | 
| 75 | 
            +
                    # e.g. { ["Post:1", "Post:2"] => [:comments, :user] }
         | 
| 70 76 | 
             
                    def eager_loadings
         | 
| 71 77 | 
             
                      Thread.current[:bullet_eager_loadings]
         | 
| 72 78 | 
             
                    end
         | 
    
        data/lib/bullet/detector/base.rb
    CHANGED
    
    
| @@ -3,16 +3,17 @@ | |
| 3 3 | 
             
            module Bullet
         | 
| 4 4 | 
             
              module Detector
         | 
| 5 5 | 
             
                class CounterCache < Base
         | 
| 6 | 
            -
                  class <<self
         | 
| 6 | 
            +
                  class << self
         | 
| 7 7 | 
             
                    def add_counter_cache(object, associations)
         | 
| 8 8 | 
             
                      return unless Bullet.start?
         | 
| 9 9 | 
             
                      return unless Bullet.counter_cache_enable?
         | 
| 10 10 | 
             
                      return unless object.bullet_primary_key_value
         | 
| 11 11 |  | 
| 12 | 
            -
                      Bullet.debug( | 
| 13 | 
            -
             | 
| 14 | 
            -
                         | 
| 15 | 
            -
                       | 
| 12 | 
            +
                      Bullet.debug(
         | 
| 13 | 
            +
                        'Detector::CounterCache#add_counter_cache',
         | 
| 14 | 
            +
                        "object: #{object.bullet_key}, associations: #{associations}"
         | 
| 15 | 
            +
                      )
         | 
| 16 | 
            +
                      create_notification object.class.to_s, associations if conditions_met?(object, associations)
         | 
| 16 17 | 
             
                    end
         | 
| 17 18 |  | 
| 18 19 | 
             
                    def add_possible_objects(object_or_objects)
         | 
| @@ -22,7 +23,10 @@ module Bullet | |
| 22 23 | 
             
                      objects = Array(object_or_objects)
         | 
| 23 24 | 
             
                      return if objects.map(&:bullet_primary_key_value).compact.empty?
         | 
| 24 25 |  | 
| 25 | 
            -
                      Bullet.debug( | 
| 26 | 
            +
                      Bullet.debug(
         | 
| 27 | 
            +
                        'Detector::CounterCache#add_possible_objects',
         | 
| 28 | 
            +
                        "objects: #{objects.map(&:bullet_key).join(', ')}"
         | 
| 29 | 
            +
                      )
         | 
| 26 30 | 
             
                      objects.each { |object| possible_objects.add object.bullet_key }
         | 
| 27 31 | 
             
                    end
         | 
| 28 32 |  | 
| @@ -6,7 +6,7 @@ module Bullet | |
| 6 6 | 
             
                  extend Dependency
         | 
| 7 7 | 
             
                  extend StackTraceFilter
         | 
| 8 8 |  | 
| 9 | 
            -
                  class <<self
         | 
| 9 | 
            +
                  class << self
         | 
| 10 10 | 
             
                    # executed when object.assocations is called.
         | 
| 11 11 | 
             
                    # first, it keeps this method call for object.association.
         | 
| 12 12 | 
             
                    # then, it checks if this associations call is unpreload.
         | 
| @@ -19,7 +19,10 @@ module Bullet | |
| 19 19 |  | 
| 20 20 | 
             
                      add_call_object_associations(object, associations)
         | 
| 21 21 |  | 
| 22 | 
            -
                      Bullet.debug( | 
| 22 | 
            +
                      Bullet.debug(
         | 
| 23 | 
            +
                        'Detector::NPlusOneQuery#call_association',
         | 
| 24 | 
            +
                        "object: #{object.bullet_key}, associations: #{associations}"
         | 
| 25 | 
            +
                      )
         | 
| 23 26 | 
             
                      if !excluded_stacktrace_path? && conditions_met?(object, associations)
         | 
| 24 27 | 
             
                        Bullet.debug('detect n + 1 query', "object: #{object.bullet_key}, associations: #{associations}")
         | 
| 25 28 | 
             
                        create_notification caller_in_project, object.class.to_s, associations
         | 
| @@ -33,7 +36,10 @@ module Bullet | |
| 33 36 | 
             
                      objects = Array(object_or_objects)
         | 
| 34 37 | 
             
                      return if objects.map(&:bullet_primary_key_value).compact.empty?
         | 
| 35 38 |  | 
| 36 | 
            -
                      Bullet.debug( | 
| 39 | 
            +
                      Bullet.debug(
         | 
| 40 | 
            +
                        'Detector::NPlusOneQuery#add_possible_objects',
         | 
| 41 | 
            +
                        "objects: #{objects.map(&:bullet_key).join(', ')}"
         | 
| 42 | 
            +
                      )
         | 
| 37 43 | 
             
                      objects.each { |object| possible_objects.add object.bullet_key }
         | 
| 38 44 | 
             
                    end
         | 
| 39 45 |  | 
| @@ -51,7 +57,10 @@ module Bullet | |
| 51 57 | 
             
                      return unless Bullet.n_plus_one_query_enable?
         | 
| 52 58 | 
             
                      return unless object.bullet_primary_key_value
         | 
| 53 59 |  | 
| 54 | 
            -
                      Bullet.debug( | 
| 60 | 
            +
                      Bullet.debug(
         | 
| 61 | 
            +
                        'Detector::NPlusOneQuery#add_inversed_object',
         | 
| 62 | 
            +
                        "object: #{object.bullet_key}, association: #{association}"
         | 
| 63 | 
            +
                      )
         | 
| 55 64 | 
             
                      inversed_objects.add object.bullet_key, association
         | 
| 56 65 | 
             
                    end
         | 
| 57 66 |  | 
| @@ -72,10 +81,11 @@ module Bullet | |
| 72 81 | 
             
                    def association?(object, associations)
         | 
| 73 82 | 
             
                      value = object_associations[object.bullet_key]
         | 
| 74 83 | 
             
                      value&.each do |v|
         | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
                        result = | 
| 84 | 
            +
                        # associations == v comparison order is important here because
         | 
| 85 | 
            +
                        # v variable might be a squeel node where :== method is redefined,
         | 
| 86 | 
            +
                        # so it does not compare values at all and return unexpected results
         | 
| 87 | 
            +
                        result =
         | 
| 88 | 
            +
                          v.is_a?(Hash) ? v.key?(associations) : associations == v
         | 
| 79 89 | 
             
                        return true if result
         | 
| 80 90 | 
             
                      end
         | 
| 81 91 |  | 
| @@ -6,7 +6,7 @@ module Bullet | |
| 6 6 | 
             
                  extend Dependency
         | 
| 7 7 | 
             
                  extend StackTraceFilter
         | 
| 8 8 |  | 
| 9 | 
            -
                  class <<self
         | 
| 9 | 
            +
                  class << self
         | 
| 10 10 | 
             
                    # check if there are unused preload associations.
         | 
| 11 11 | 
             
                    #   get related_objects from eager_loadings associated with object and associations
         | 
| 12 12 | 
             
                    #   get call_object_association from associations of call_object_associations whose object is in related_objects
         | 
| @@ -29,7 +29,10 @@ module Bullet | |
| 29 29 | 
             
                      return unless Bullet.unused_eager_loading_enable?
         | 
| 30 30 | 
             
                      return if objects.map(&:bullet_primary_key_value).compact.empty?
         | 
| 31 31 |  | 
| 32 | 
            -
                      Bullet.debug( | 
| 32 | 
            +
                      Bullet.debug(
         | 
| 33 | 
            +
                        'Detector::UnusedEagerLoading#add_eager_loadings',
         | 
| 34 | 
            +
                        "objects: #{objects.map(&:bullet_key).join(', ')}, associations: #{associations}"
         | 
| 35 | 
            +
                      )
         | 
| 33 36 | 
             
                      bullet_keys = objects.map(&:bullet_key)
         | 
| 34 37 |  | 
| 35 38 | 
             
                      to_add = []
         | 
    
        data/lib/bullet/mongoid4x.rb
    CHANGED
    
    | @@ -23,7 +23,7 @@ module Bullet | |
| 23 23 | 
             
                    end
         | 
| 24 24 |  | 
| 25 25 | 
             
                    def each(&block)
         | 
| 26 | 
            -
                      return to_enum unless  | 
| 26 | 
            +
                      return to_enum unless block
         | 
| 27 27 |  | 
| 28 28 | 
             
                      records = []
         | 
| 29 29 | 
             
                      origin_each { |record| records << record }
         | 
| @@ -37,9 +37,7 @@ module Bullet | |
| 37 37 |  | 
| 38 38 | 
             
                    def eager_load(docs)
         | 
| 39 39 | 
             
                      associations = criteria.inclusions.map(&:name)
         | 
| 40 | 
            -
                      docs.each  | 
| 41 | 
            -
                        Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations)
         | 
| 42 | 
            -
                      end
         | 
| 40 | 
            +
                      docs.each { |doc| Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations) }
         | 
| 43 41 | 
             
                      Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
         | 
| 44 42 | 
             
                      origin_eager_load(docs)
         | 
| 45 43 | 
             
                    end
         | 
| @@ -50,9 +48,7 @@ module Bullet | |
| 50 48 |  | 
| 51 49 | 
             
                    def get_relation(name, metadata, object, reload = false)
         | 
| 52 50 | 
             
                      result = origin_get_relation(name, metadata, object, reload)
         | 
| 53 | 
            -
                      if metadata.macro !~ /embed/
         | 
| 54 | 
            -
                        Bullet::Detector::NPlusOneQuery.call_association(self, name)
         | 
| 55 | 
            -
                      end
         | 
| 51 | 
            +
                      Bullet::Detector::NPlusOneQuery.call_association(self, name) if metadata.macro !~ /embed/
         | 
| 56 52 | 
             
                      result
         | 
| 57 53 | 
             
                    end
         | 
| 58 54 | 
             
                  end
         | 
    
        data/lib/bullet/mongoid5x.rb
    CHANGED
    
    | @@ -23,7 +23,7 @@ module Bullet | |
| 23 23 | 
             
                    end
         | 
| 24 24 |  | 
| 25 25 | 
             
                    def each(&block)
         | 
| 26 | 
            -
                      return to_enum unless  | 
| 26 | 
            +
                      return to_enum unless block
         | 
| 27 27 |  | 
| 28 28 | 
             
                      records = []
         | 
| 29 29 | 
             
                      origin_each { |record| records << record }
         | 
| @@ -37,9 +37,7 @@ module Bullet | |
| 37 37 |  | 
| 38 38 | 
             
                    def eager_load(docs)
         | 
| 39 39 | 
             
                      associations = criteria.inclusions.map(&:name)
         | 
| 40 | 
            -
                      docs.each  | 
| 41 | 
            -
                        Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations)
         | 
| 42 | 
            -
                      end
         | 
| 40 | 
            +
                      docs.each { |doc| Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations) }
         | 
| 43 41 | 
             
                      Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
         | 
| 44 42 | 
             
                      origin_eager_load(docs)
         | 
| 45 43 | 
             
                    end
         | 
| @@ -50,9 +48,7 @@ module Bullet | |
| 50 48 |  | 
| 51 49 | 
             
                    def get_relation(name, metadata, object, reload = false)
         | 
| 52 50 | 
             
                      result = origin_get_relation(name, metadata, object, reload)
         | 
| 53 | 
            -
                      if metadata.macro !~ /embed/
         | 
| 54 | 
            -
                        Bullet::Detector::NPlusOneQuery.call_association(self, name)
         | 
| 55 | 
            -
                      end
         | 
| 51 | 
            +
                      Bullet::Detector::NPlusOneQuery.call_association(self, name) if metadata.macro !~ /embed/
         | 
| 56 52 | 
             
                      result
         | 
| 57 53 | 
             
                    end
         | 
| 58 54 | 
             
                  end
         | 
    
        data/lib/bullet/mongoid6x.rb
    CHANGED
    
    | @@ -23,7 +23,7 @@ module Bullet | |
| 23 23 | 
             
                    end
         | 
| 24 24 |  | 
| 25 25 | 
             
                    def each(&block)
         | 
| 26 | 
            -
                      return to_enum unless  | 
| 26 | 
            +
                      return to_enum unless block
         | 
| 27 27 |  | 
| 28 28 | 
             
                      records = []
         | 
| 29 29 | 
             
                      origin_each { |record| records << record }
         | 
| @@ -37,9 +37,7 @@ module Bullet | |
| 37 37 |  | 
| 38 38 | 
             
                    def eager_load(docs)
         | 
| 39 39 | 
             
                      associations = criteria.inclusions.map(&:name)
         | 
| 40 | 
            -
                      docs.each  | 
| 41 | 
            -
                        Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations)
         | 
| 42 | 
            -
                      end
         | 
| 40 | 
            +
                      docs.each { |doc| Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations) }
         | 
| 43 41 | 
             
                      Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
         | 
| 44 42 | 
             
                      origin_eager_load(docs)
         | 
| 45 43 | 
             
                    end
         | 
| @@ -50,9 +48,7 @@ module Bullet | |
| 50 48 |  | 
| 51 49 | 
             
                    def get_relation(name, metadata, object, reload = false)
         | 
| 52 50 | 
             
                      result = origin_get_relation(name, metadata, object, reload)
         | 
| 53 | 
            -
                      if metadata.macro !~ /embed/
         | 
| 54 | 
            -
                        Bullet::Detector::NPlusOneQuery.call_association(self, name)
         | 
| 55 | 
            -
                      end
         | 
| 51 | 
            +
                      Bullet::Detector::NPlusOneQuery.call_association(self, name) if metadata.macro !~ /embed/
         | 
| 56 52 | 
             
                      result
         | 
| 57 53 | 
             
                    end
         | 
| 58 54 | 
             
                  end
         |