Why large Django projects need a data (prefetching) layer with Flávio Juvenal - DjangoCon US 2022

Learn how to improve performance in large Django projects by introducing a data layer, utilizing prefetching, annotations, and virtual models with Flávio Juvenal at DjangoCon US 2022.

Key takeaways
  • Django REST Framework‘s “don’t repeat yourself” principle can lead to complex code and maintenance issues.
  • Prefetching and annotations are crucial for performance and preventing n+1 queries.
  • Virtual models can help decouple query sets from serializers, making code more maintainable.
  • Django virtual models can be used to prefetch and annotate data, and even support custom functions.
  • The getOptimizedQuerySet method can be used to optimize query sets and prevent unnecessary prefetches.
  • Using mixins can help reuse code and reduce the need for nested serializers.
  • The serializer method field can be used to nest serializers and prefetch data.
  • Django readers can be used to project complex data and prevent n+1 queries.
  • The prefetch_related method can be used to prefetch related objects and prevent n+1 queries.
  • The annotate method can be used to add custom annotations to query sets.
  • The select_related method can be used to select related objects and prevent n+1 queries.
  • The deferred fields feature can be used to defer loading of related objects and prevent n+1 queries.
  • The Strawberry Django Plus project provides a more explicit way of handling prefetching and annotations.
  • The Django virtual models library provides a way to define virtual models and use them to prefetch and annotate data.
  • The prefetchers library provides a way to define prefetchers and use them to prefetch data.
  • The annotations library provides a way to define annotations and use them to annotate data.
  • The query_set method can be used to define a query set and use it to prefetch and annotate data.
  • The serializer method can be used to define a serializer and use it to serialize data.
  • The view_set method can be used to define a view set and use it to handle requests and responses.