mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 00:53:56 +00:00
migrations: Fix performance of migration 0436.
This was doing bulk_create in a loop for each realm, which is too slow on very large servers. Just do a single bulk_create with a reasonable batch_size at the end.
This commit is contained in:
committed by
Tim Abbott
parent
18d8fbc74b
commit
d0e9a77a57
@@ -11,12 +11,13 @@ def fill_RealmAuthenticationMethod_data(
|
|||||||
) -> None:
|
) -> None:
|
||||||
Realm = apps.get_model("zerver", "Realm")
|
Realm = apps.get_model("zerver", "Realm")
|
||||||
RealmAuthenticationMethod = apps.get_model("zerver", "RealmAuthenticationMethod")
|
RealmAuthenticationMethod = apps.get_model("zerver", "RealmAuthenticationMethod")
|
||||||
for realm in Realm.objects.order_by("id"):
|
|
||||||
rows_to_create = []
|
rows_to_create = []
|
||||||
|
for realm in Realm.objects.order_by("id"):
|
||||||
for key, value in realm.authentication_methods.iteritems():
|
for key, value in realm.authentication_methods.iteritems():
|
||||||
if value:
|
if value:
|
||||||
rows_to_create.append(RealmAuthenticationMethod(name=key, realm_id=realm.id))
|
rows_to_create.append(RealmAuthenticationMethod(name=key, realm_id=realm.id))
|
||||||
RealmAuthenticationMethod.objects.bulk_create(rows_to_create)
|
|
||||||
|
RealmAuthenticationMethod.objects.bulk_create(rows_to_create, batch_size=10000)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|||||||
Reference in New Issue
Block a user