export: Pass "user_profile" as arg to select_related call for Subscription.

This commit adds code to pass all the required arguments to
select_related call for Subscription objects such that only
the required related fields are fetched from the database.

Previously, we did not pass any arguments to select_related,
so all the directly and indirectly related fields were fetched
when many of them were actually not being used and made the
query unnecessarily complex.
This commit is contained in:
Sahil Batra 2023-08-01 15:40:55 +05:30 committed by Tim Abbott
parent ebd91b152c
commit 35559ae324
1 changed files with 2 additions and 2 deletions

View File

@ -1120,10 +1120,10 @@ def custom_fetch_huddle_objects(response: TableData, context: Context) -> None:
# Mark all Huddles whose recipient ID contains a cross-realm user.
unsafe_huddle_recipient_ids = set()
for sub in Subscription.objects.select_related().filter(
for sub in Subscription.objects.select_related("user_profile").filter(
recipient__in=realm_huddle_recipient_ids
):
if sub.user_profile.realm != realm:
if sub.user_profile.realm_id != realm.id:
# In almost every case the other realm will be zulip.com
unsafe_huddle_recipient_ids.add(sub.recipient_id)