mirror of https://github.com/zulip/zulip.git
migrations: Fix missing select_related in RealmAuditLog migration.
This migration accidentally did a bunch of database queries fetching data in a loop.
This commit is contained in:
parent
5e5ca48063
commit
a36cf3b492
|
@ -15,7 +15,9 @@ def backfill_subscription_log_events(apps, schema_editor):
|
|||
Subscription = apps.get_model('zerver', 'Subscription')
|
||||
Message = apps.get_model('zerver', 'Message')
|
||||
|
||||
for sub in Subscription.objects.filter(recipient__type=2):
|
||||
subs_query = Subscription.objects.select_related(
|
||||
"user_profile", "user_profile__realm", "recipient").filter(recipient__type=2)
|
||||
for sub in subs_query:
|
||||
RealmAuditLog.objects.create(realm=sub.user_profile.realm,
|
||||
modified_user=sub.user_profile,
|
||||
modified_stream_id=sub.recipient.type_id,
|
||||
|
@ -26,8 +28,7 @@ def backfill_subscription_log_events(apps, schema_editor):
|
|||
|
||||
event_last_message_id = Message.objects.aggregate(Max('id'))['id__max']
|
||||
migration_time_for_deactivation = timezone_now()
|
||||
for sub in Subscription.objects.filter(recipient__type=2,
|
||||
active=False):
|
||||
for sub in subs_query.filter(active=False):
|
||||
RealmAuditLog.objects.create(realm=sub.user_profile.realm,
|
||||
modified_user=sub.user_profile,
|
||||
modified_stream_id=sub.recipient.type_id,
|
||||
|
|
Loading…
Reference in New Issue