June 2024
Intermediate to advanced
456 pages
11h 34m
English
While manual checks are useful, the Rails ecosystem has many gems and tools to detect N+1 queries. These tools could be integrated into your development flow to add some automation.
The Ruby gem Prosopite[124] is an N+1 detection gem that’s been added to Rideshare, along with pg_query,[125] which it depends on.
Let’s see if Prosopite picks up this deliberate N+1. Run the code again in Rideshare from bin/rails console inside of a Prosopite block, as this shows. Set Prosopite.rails_logger = true.
| | Prosopite.rails_logger = true |
| | |
| | Prosopite.scan do |
| | Vehicle.all.each do |vehicle| |
| | vehicle.vehicle_reservations.count |
| | end |
| | end |
Hopefully, you saw that Prosopite ...
Read now
Unlock full access