Menu

Django 6.1's FETCH_PEERS against my own select_related
📰

Django 6.1's FETCH_PEERS against my own select_related

DEV Community: django·Remdore·about 11 hours ago
#B2xxkKJp
#devtodjango#devto#dev#queries#fetch_peers
Reading 0:00
15s threshold

Django 6.1 added fetch modes. With FETCH_PEERS , when you touch a foreign key on one object from a queryset, Django loads that relation for every object the queryset returned, in one query. The classic N+1 loop becomes 2 queries without you writing select_related .

My football quiz site, ExtraTime, has 621 select_related calls and 103 prefetch_related calls in its Django API, outside the tests. I wanted to know how much of that work the new mode would have done for me.

How I measured it

The API has 6,635 tests, and a lot of them call the real endpoints through Django's test client.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.