Optimizing your webapp by using django-debug-toolbar
summary
Page-level SQL inspection with django-debug-toolbar reveals the list view issues: 52 queries for a simple page and 44 for a detail page. Rewriting queries with select_related collapses repeated foreign-key fetches down to 2 SQL statements; using prefetch_related pulls many-to-many and reverse-FK sets in separate batched queries and drops the detail view to 7 queries. The demo shows concrete line-level query locations, simple view changes, and large, measurable speed gains.
AI-written summary · about
chapters (15)
- 0:00Start
- 0:06Diamond Sponsor
- 0:22Christopher Adams
- 2:06Manage your own expectations for tools
- 2:41Unicorns don't exist
- 3:26Abstraction layers
- 6:57Hits the database (QuerySet is "evaluated")
- 8:25Models
- 9:24List View
- 9:38List Template
- 10:10Detail View
- 10:33Detail Template
- 16:26select_related
- 19:24prefetch_related
- 21:36Summary
related talks
26mA Related Matter: Optimizing your webapp
28mBut, why is the admin slow?
43mOptimize Python & Django apps with Postgres superpowers
28mThe life of a web request - techniques for measuring and improving Django application performance
29mMaking smarter queries with advanced ORM resources
23mEntomology 101: Effective Bug Hunting
28mSaved you a click (or three): Supercharging the Django admin with actions and views
27mDjango - Customise your SQL
