tests: Pass required args to select_related call for Message objects.

This commit adds code to pass all the required arguments to
select_related call for Message 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 22:04:17 +05:30 committed by Tim Abbott
parent a6df377688
commit 0e23280b4f
2 changed files with 6 additions and 3 deletions

View File

@ -282,7 +282,8 @@ class EditMessageTest(EditMessageTestCase):
self.send_stream_message(self.notification_bot(realm), stream_name, "Message three")
)
messages = [
Message.objects.select_related().get(id=message_id) for message_id in message_ids
Message.objects.select_related(*Message.DEFAULT_SELECT_RELATED).get(id=message_id)
for message_id in message_ids
]
# Check number of queries performed

View File

@ -1454,7 +1454,8 @@ class MessageAccessTests(ZulipTestCase):
message_ids = [message_one_id, message_two_id]
messages = [
Message.objects.select_related().get(id=message_id) for message_id in message_ids
Message.objects.select_related("recipient").get(id=message_id)
for message_id in message_ids
]
with self.assert_database_query_count(2):
@ -1512,7 +1513,8 @@ class MessageAccessTests(ZulipTestCase):
message_ids = [message_one_id, message_two_id]
messages = [
Message.objects.select_related().get(id=message_id) for message_id in message_ids
Message.objects.select_related("recipient").get(id=message_id)
for message_id in message_ids
]
# All public stream messages are always accessible