From 7ff5423e2107fa3c5c461bcf0d301676812ef43c Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 1 Aug 2023 21:09:58 +0530 Subject: [PATCH] topic: Pass 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. --- zerver/lib/topic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index da4c0404cc..4c9506269b 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -160,7 +160,9 @@ def update_messages_for_topic_edit( if propagate_mode == "change_later": propagate_query = propagate_query & Q(id__gt=edited_message.id) - messages = Message.objects.filter(propagate_query).select_related() + messages = Message.objects.filter(propagate_query).select_related( + *Message.DEFAULT_SELECT_RELATED + ) update_fields = ["edit_history", "last_edit_time"]