Skip to content

Add Prosopite for N+1 query detection - #1358

Open
jaredlt wants to merge 3 commits into
mainfrom
add-prosopite
Open

Add Prosopite for N+1 query detection#1358
jaredlt wants to merge 3 commits into
mainfrom
add-prosopite

Conversation

@jaredlt

@jaredlt jaredlt commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Before, generated apps relied on strict_loading_by_default with the :n_plus_one_only mode for N+1 protection, which raises when an association is lazily loaded from a collection-loaded record. However, strict loading does not detect all N+1s.

Now, Prosopite scans web requests & Sidekiq jobs in development and test via its middleware. Detections are logged in development and raise Prosopite::NPlusOneQueriesError in test, so new apps fail their test suite on N+1 queries that strict loading can't see.

Closes: #1325

Before, generated apps relied on strict_loading_by_default with the
:n_plus_one_only mode for N+1 protection, which raises when an
association is lazily loaded from a collection-loaded record. However,
strict loading does not detect [all] N+1s.

Now, [Prosopite] scans web requests & Sidekiq jobs in development and
test via its middleware. Detections are logged in development and raise
`Prosopite::NPlusOneQueriesError` in test, so new apps fail their test
suite on N+1 queries that strict loading can't see.

[all]: rails/rails#56094
[Prosopite]: https://github.com/charkost/prosopite

@stevepolitodesign stevepolitodesign left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want to remove these lines too:

environment "config.active_record.strict_loading_by_default = true"
environment "config.active_record.strict_loading_mode = :n_plus_one_only"

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@stevepolitodesign stevepolitodesign left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just one more set of suggestions, then we're good!

Comment thread FEATURES.md
Comment thread lib/templates/config/initializers/sidekiq.rb Outdated
Comment thread lib/templates/web.rb Outdated
@jaredlt

jaredlt commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@stevepolitodesign thanks for taking another look at this! All feedback should be addressed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants