Django and HTMX #9 - Database Query Optimization with django-debug-toolbar

preview_player
Показать описание
In this video, we will use the django-debug-toolbar extension to fix some database performance issues in our application. We will demonstrate how to install and use django-debug-toolbar, and will use this package to help prevent the N+1 problem, and discover where our database queries can be improved.

We will see how to use Django's ORM to help remedy these problems, including:
- Prefetching related models with the prefetch_related() function
- Using the bulk_update() function to update multiple changed models in a single query.

Cutting down on database I/O is a vital practice for achieving optimal application performance!

Code will be available on the "Video #9" directory in the Github repository linked below.

▶️ Full Playlist:

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 intro
00:12 setting up django-debug-toolbar
01:35 preventing n+1 problem using prefetch_related()
03:57 optimizing sort queries

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:

#django #htmx #python
Рекомендации по теме
Комментарии
Автор

This is my favorite playlist on Youtube for Django dev. Thank you for the great content and keep up the good work! :)

sudoscientist
Автор

Laughed more than necessary at "2 hours later" :D Awesome series!

eimantasnejus
Автор

Brilliant! From 305 queries to 6 :-) Great!

laszlo.laszlo
Автор

wow. thanks dude. I was not aware of the bulk_update function or the n+1 problem. This is so useful!

AyazAmlani
Автор

This is actually the best Video in this series, why I'm I not even aware of any of these.

Thanks for this amazing series.

defidelity
Автор

i'm glad found this channel from django ninja docs. As a beginner, your contents are really helpful for me, thankyou.. you deserve more sub, keep it up!

Ketzunouka
Автор

This was excellent! No one really teaches this so thank you for running through it.
I'm also loving this playlist so far, one of my favorites! I spent so much time learning JavaScript and Vue.js when I could have simply learnt htmx to do the same thing so much quicker and easier!

Peterstavrou
Автор

You have been an invaluable resource in my adventure into Django land. Thank you so much for your time and efforts with this playlist!

Crunchy
Автор

There should be a warning at the start of the series, that n+1 and bulk update problems will be solved later ;-) Being a curious person, I had to learn about the Debug Toolbar earlier, because I wanted to see what SQL statements get generated. It would take me much less time after seeing this episode. I wonder if I will learn about Faker (needed in previous lesson).

brablc
Автор

This is awesome. I hope we see more Django query optimization tutorials in the future.

MrValVet
Автор

this is very informative content, good job man

esmael
Автор

Oh my, this was a real lesson. Learning a lot with you

mayconblopes_
Автор

you are extremely great in Django, I wish I could do the same😊

aafan.kuware
Автор

Very nice content and aplications uses! Stay up with the good work. Thank you for sharing your experience.

From Brazil =D

viniciusstucki
Автор

Loving this series, been keen to implement more htmx with django. Will you be doing the independent dropdown? Thanks!

chazzwhu
Автор

Really enjoying this series, liking htmx more and more as I discover it.

I was wondering if you could do a bit in the next episode where you show how to fix the list with pagination when going back from film details/dragging and dropping to reorder. I've been playing around with it a bit trying to get it to work properly, but it's still kind of borked.

owenjones
Автор

I love the series, thank you very much!

There's one line of code I can't put in my head properly:
page_number = len(film_pks_order) / settings.PAGINATE_BY

This line is in the pagination section of a sort function in a films app. It would be great if you could answer what we count here an why. Thanks.

lexe
Автор

I was really enjoying your videos, so I decided that I wanted to give HTMX a try. I cloned your files for video #9 and tried to install the dependencies, but these older versions failed to install... when I installed the new versions of the dependencies, there were numerous bugs in the code. Adding a movie displays the same movie twice in the browser, even though only one record exists in the database. Deleting the movie clones the input forms and places them to the right.

Very strange. It might be time to update this tutorial.

tylersen
Автор

Hi mate so good content, how about safety crf tokens? Is this htmx safe to use? I am confused.

blabla-kkbl
Автор

Have been following the series. Seems like still sort doesn't work well with infinite scrolling. I still get numbers all mixed up when I infinite-scroll down after some draging and dropping. I wonder if it's just me or anyone else has had this issue.

LegionLeague
join shbcf.ru