A Related Matter: Optimizing your webapp
summary
Shows how django-debug-toolbar surfaces an N+1 problem in a toy blog app and how using select_related()/prefetch_related() collapses ~50 SQL queries down to two or seven, with concrete examples for foreign keys, many‑to‑many likers and comment submitters. Demonstrates QuerySet laziness and immutability, logging and DB general‑log techniques to capture queries, explains that prefetch assembles related rows in Python, and warns about pathological users and watching 95th/99th percentile latency.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 1:29Django tool and limits
- 2:54Django query sets
- 4:43Debugging SQL queries
- 8:19N+1 problems with toolbar
- 12:52Fix N+1 with select_related
- 15:21Optimize many-to-many with prefetch_related
- 20:14Complex query optimizations
- 22:00Query optimization summary
- 23:05Q&A prefetch_related
related talks
23mOptimizing your webapp by using django-debug-toolbar
27mFinding and fixing an N+1 problem in the Django docs
49mPrefetching for Fun and Profit
29mN+1 Problem in Django Rest Framework
43mOptimize Python & Django apps with Postgres superpowers
17mOff the Beaten Path: Exploring Unusual Roads to Django Performance
29mMaking smarter queries with advanced ORM resources
42mA Nice Problem to Have: Django Under Heavy Load
