mirror of https://github.com/zulip/zulip.git
bulk_create: Use a (large) batch_size with MySQL.
(imported from commit 529fef7dd55bb8a5f4e286f7c896f4b14b0d1b8d)
This commit is contained in:
parent
e7abe13cd6
commit
95c39cbc76
|
@ -3,9 +3,9 @@ from django.conf import settings
|
|||
# Django bulk_create method accepts a batch_size directly.
|
||||
def batch_bulk_create(cls, cls_list, batch_size=150):
|
||||
if "sqlite" not in settings.DATABASES["default"]["ENGINE"]:
|
||||
# We only need to do the below batching nonsense with sqlite.
|
||||
cls.objects.bulk_create(cls_list)
|
||||
return
|
||||
# We don't need a low batch size with mysql, but we do need
|
||||
# one to avoid "MySQL Server has gone away" errors
|
||||
batch_size = 2000
|
||||
while len(cls_list) > 0:
|
||||
current_batch = cls_list[0:batch_size]
|
||||
cls.objects.bulk_create(current_batch)
|
||||
|
|
Loading…
Reference in New Issue