Allow cleaning backtraces used to identify N+1 queries#79
Allow cleaning backtraces used to identify N+1 queries#79tf wants to merge 1 commit intocharkost:mainfrom
Conversation
Some gems cache missing methods after the first call. This can cause
Prosopite to miss duplicate queries. For example, the N+1 query for
`author` in the following `builder` template goes unnoticed if there
are two posts since `xml.post` is a missing method that gets cached
for the second call (see [1]).
```ruby
@posts.each do |post|
xml.post do
xml.author post.author.name
end
end
```
Add `location_backtrace_cleaner` config option to modify backtraces
that are used to identify queries. This allows to either silence
problematic lines or even just use the backtrace inside the
application itself:
```ruby
Prosopite.location_backtrace_cleaner = Rails.backtrace_silencer
```
[1] https://github.com/jimweirich/builder/blob/c80100f8205b2e918dbff605682b01ab0fabb866/lib/builder/xmlbase.rb#L91
|
Alternatively, one could always create associations with at least three records in tests. This bloats test setup, though, and is easy to forget. Only using application backtraces means erring on the side of caution. Happy to take suggestions regarding the name of the option. Having both a One alternative I considered is to instead add an option to allow replacing the whole I also considered adding an option like |
|
Also happy to add a README section if this is not considered too much of an edge case. |
Some gems cache missing methods after the first call. This can cause Prosopite to miss duplicate queries. For example, the N+1 query for
authorin the followingbuildertemplate goes unnoticed if there are two posts sincexml.postis a missing method that gets cached for the second call (see [1]).Add
location_backtrace_cleanerconfig option to modify backtraces that are used to identify queries. This allows to either silence problematic lines or even just use the backtrace inside the application itself:[1] https://github.com/jimweirich/builder/blob/c80100f8205b2e918dbff605682b01ab0fabb866/lib/builder/xmlbase.rb#L91