Learning center

Can I write an AI review rule for N+1 database queries?

Yes. Ask the reviewer to follow a collection query into the loop or serializer that consumes each row. Require it to identify the relationship access that could cause one extra query per result.

Trace the list endpoint#

Imagine a Django endpoint that fetches orders and renders each customer's name. A reviewer flags the template's access to the customer relation. Before accepting the finding, follow the queryset from the view to the template. The relation might already have been loaded by the queryset that the caller supplies.

CodeRabbit's Django example shows where to put queryset review instructions. Make yours specific to a list endpoint your team owns. To verify a finding, count queries with one order and again with several orders belonging to different customers. Record the data shape with the count so a maintainer can repeat the comparison. CodeRabbit’s Django configuration example

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading