What if we separate detection and reporting?
Closed this issue · 3 comments
May I suggest adding silent N+1 detection to the public API?
I don't feel a need to log
or raise
on N+1, but instead I'd rather have a report and build my own notifications based on it.
Example:
Prosopite.scan do
NPlusOne.perform
end # => return report in form of queries, caller and count
Prosopite.scan! do
NPlusOne.perform
end # => run reporting via logging or raising or both.
Further to this, it'd be great if we could have a pattern for selectively testing for n+1s in only certain rspec tests - not everywhere.
In bullet this is done something like this:
Bullet.profile do
get :index
expect(Bullet.warnings).to be_empty
end
Would you consider accepting patches to this effect, @charkost ?
It seems like I can do something like this as follows, but it doesn't seem ideal to start mucking around with .tc
and the contents of that hash.
Prosopite.scan do
get :index
expect(json["data"].count).to eq(3)
end
expect(Prosopite.tc[:prosopite_notifications].count).to eq(0)
@charkost Was wondering if you thought a PR to wrap methods for the above would be useful? Thanks!
The changes were a lot, so I did a rebuilt of that library for my purposes and pg support only.
https://github.com/prikha/n_one