~/talk

Choose, and choose quickly: Optimising ModelChoiceField

Talkat DjangoCon Europe 2020 Β· 2020-09-18..09-19Β· [frontend-architecture, django]
slides:none on file

Django REST Framework browseable form, django-filter forms and admin list_editable slow when ModelChoiceField fetches related rows: a suburb dataset with 17,871 rows triggers ~1,002 SQL queries (DRF cutoff) or ~17,871 queries (django-filter) and the admin can hang. Solutions: use select_related / prefetch_related to cut queries (1,002 β†’ 4; 17,871 β†’ 6), compute choices once per formset to don't repeat work (35 β†’ 11), or precompute and cache choices to do the work early (down to ~5 queries).

AI-written summary Β· about

  1. 0:00Introduction and setup
  2. 2:52What is ModelChoiceField
  3. 6:43Example one: DRF serializer form
  4. 7:46Example two: Django filter form
  5. 9:11Example three: Django admin list editable
  6. 11:38Strategy one: Do less work
  7. 15:48Strategy two: Don't repeat work
  8. 18:54Strategy three: Do work early
  9. 20:15Summary and takeaways
  10. 21:40Q&A: Automatic prefetching
  11. 24:30Q&A: Only queries optimization
  12. 26:46Q&A: Handling large choice lists
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark β€” the status bar button does the same
← β†’
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter β€” or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.