Speed up your database inserts with Django ORM's bulk_create()

preview_player
Показать описание
In this short video I show you a 36X speed up of inserting one million+ rows into a database using Django's ORM.

Docs: "This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many objects there are), and returns created objects as a list, in the same order as provided."

By the way, since Django 4.1 there is also an asynchronous version of this - abulk_create() - but I could not just "plug that in" without getting a "coroutine ... was never awaited" warning, nor am I fully up2speed yet with Django's new async capabilities (link below), hence to be continued ...

Links:

Stay tuned for another video about the N+1 query performance problem in Django and how to fix it.

---

And last but not least, we appreciate any feedback to make our YouTube content better 💡
Рекомендации по теме
Комментарии
Автор

Very useful. Thank you! Went from a minute to insert about 4000 entries to 4 seconds.

emilagne
Автор

Amazing video Bob! Keep up. Really useful

juanjoseexpositogonzalez
Автор

Another way of doing the same thing is by wrapping the whole code in transaction.atomic() block
this way it creates a single operation.

achalpathak