Closed technicalpickles closed 12 months ago
I understand the need to ignore specific N+1 queries at runtime. However, isn't the existing Prosopite.pause
enough for that job?
Strictly speaking, you can get the same effect, but the interface would be different:
Leg.last(10).each do |l|
Prosopite.pause { l.chair }
end
It feels natural to be able to chain it on a query like you do other scopes and helpers. It might be possible to have a class method that wraps the actual execution of the relationship to call Prosopite.pause
but I'm not sure how to implement that yet.
This is an extraction of some code we use with prosopite internally. There are a few places where we wanted to allow N+1, especially when it is outside of the normal web requests.
To do this, we add a class method to
ActiveRecord::Base
to add an annotation, and then we check it while checking against ignored queries.Maybe not strictly necessary for this, but I also started a Railtie for prosopite for any rails configuration to be registered. That is where ActiveRecord::Base adds our module.
I also added zeitwerk for autoloading.
cc @geshwho who implemented this initially