find_n_plus_one
Scan Django templates for relation traversals inside loops that trigger extra queries, flagging potential N+1 hotspots by resolving attribute chains against model relationships.
Instructions
Find relation traversals in a template that each cost a query.
Resolves attribute chains against the real model graph and flags the ones
that cross a relation inside a loop, which is where N+1 queries come from.
Reports candidates: whether a crossing really costs a query depends on the
queryset in the view, which this does not read.
Args:
template_path: path to the template file.
root_models: context variable to model label, e.g.
{"orders": "shop.Order"}. Loop variables inherit from these.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| root_models | Yes | ||
| template_path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||