How to fix N+1 rails

768 Views Asked by At

I have a specific inlcudes in my controller for contentType model. I need to catch all of content suites in this page with preloading. This is a fetch method for it:

def fetch_content_suites
    ContentSuite
      .includes(:tools)
      .where(tools: { content_type_id: content_type.id })
  end

ContentSuite is a parent class here. It has has_many published_tools. In model it looks like:

has_many :tools, -> { distinct }, through: :toolkits, class_name: "Tool", source: :tools

ContentSuite -> Toolkit -> Tool. (I made a custom association to access to tool through the toolkits for content_suite) Tools and toolkits has also many to many association.

This includes works pretty good, only 2 queries in this page. No any bullet errors when browsing/in server logs. But when I'm trying to run the specs for it a get:

Bullet::Notification::UnoptimizedQueryError:
       user: damirnurgaliev
       GET /content_suites/85
       USE eager loading detected
         ContentSuite => [:toolkits]
         Add to your finder: :includes => [:toolkits]

Is it a bullet bug or my fault? Thanks everyone.

0

There are 0 best solutions below