Performance: Database query optimization with select_related
HIGH IMPACT
This affects the speed of database queries and reduces the number of queries sent to the database, improving page load time.
books = Book.objects.select_related('author').all() for book in books: author_name = book.author.name # no extra queries
books = Book.objects.all() for book in books: author_name = book.author.name # triggers a query per book
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Without select_related | N/A | N/A | Blocks rendering waiting for multiple queries | [X] Bad |
| With select_related | N/A | N/A | Faster rendering due to fewer queries | [OK] Good |