---
title: "Can I write an AI review rule for N+1 database queries? | Proofline"
description: "Yes. Ask the reviewer to follow a collection query into the loop or serializer that consumes each row."
url: https://proofline.sh/learn/review-database-query-rules/
---

[Learning center](/learn/)

# 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.

Code review The Proofline team November 19, 2026 1 min read

## 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](https://docs.coderabbit.ai/configuration/examples/django)

## 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](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Can different packages in a monorepo have different AI review rules?](/learn/monorepo-review-rules/)
    
    Code review The Proofline team November 19, 2026 1 min read
    
-   ### [How can I stop an AI reviewer from repeating low-value comments?](/learn/reduce-ai-review-noise/)
    
    Code review The Proofline team November 19, 2026 1 min read
