palkan / n_plus_one_control

RSpec and Minitest matchers to prevent N+1 queries problem
MIT License
555 stars 20 forks source link

[Question] What is the scale factor for? #32

Closed victorhazbun closed 4 years ago

victorhazbun commented 4 years ago

Can you please explain what is the scale factor for?

Thanks.

palkan commented 4 years ago

The way n_plus_one_control works is the following:

So, if we take a look at the example in Readme:

context "N+1", :n_plus_one do
  # Here is how we use scale factors: we generate the different number of records
  # (assuming that the code above load them all and potentially load the children associations
  #  thus producing N+1)
  populate { |n| create_list(:post, n) }

  specify do
    expect { get :index }.to perform_constant_number_of_queries
  end
end