charkost / prosopite

:mag: Rails N+1 queries auto-detection with zero false positives / false negatives
Apache License 2.0
1.53k stars 46 forks source link

Add query counts and maximum queries to log configuration #74

Open emilong opened 11 months ago

emilong commented 11 months ago

While using prosopite on an application with many N+1s, I wanted to focus my efforts on the N+1s with the most associated queries, so I added a count of queries.

I also found that I really only needed one query per N+1 to debug each issue, so I added a configuration to limit the number of queries logged.

The result looks something like this:

W, [2023-11-09T17:48:23.795072 #338497]  WARN -- : N+1 queries detected (20):
  SELECT "legs".* FROM "legs" WHERE "legs"."chair_id" = ? ORDER BY "legs"."id" ASC LIMIT ?
Call stack:

with this configuration:

Prosopite.display_query_count = true
Prosopite.display_max_n_queries = 1

I decided to make them both optional in case anyone depends on the existing format.