Faster Django Websites Using simple SQL Optimization

Опубликовано: 28 Сентябрь 2024
на канале: Emmanuel Okiche
5,202
111

In this video, we would learn how to reduce the number of times our app hits the database to fetch related resources by reducing the number of SQL queries generated by our request.
This in turn would reduce to time to get db related resources and make our apps faster.

We would achieve this using Django's Querysets method: select_related and prefetch_related.

NOTE: To avoid repetition, you could create a custom model manager for the specific model. I used it directly here just for demonstration.

Link to the docs on DB optimization:
https://docs.djangoproject.com/en/2.2...


Thumbnail Photo by Pietro Mattia on Unsplash