mirror of https://github.com/zulip/zulip.git
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:
parent
a6df377688
commit
0e23280b4f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue