messages: Stop joining through every table.

Calling `.select_related()` with no arguments joins through every
possible table, recursively.  In this case, this currently produces a
query which joins through forty-three tables.

This is rather inefficient, particularly for what is a very common
call which should be very fast.

No callsite depends on having prefetched any joined table on the
object; drop all of the joins.

(cherry picked from commit 6ace34c374)
This commit is contained in:
Alex Vandiver
2024-03-22 05:27:40 +00:00
committed by Tim Abbott
parent 105e699ac6
commit ad21451d01

View File

@@ -621,9 +621,7 @@ def get_usermessage_by_message_id(
user_profile: UserProfile, message_id: int
) -> Optional[UserMessage]:
try:
return UserMessage.objects.select_related().get(
user_profile=user_profile, message_id=message_id
)
return UserMessage.objects.get(user_profile=user_profile, message_id=message_id)
except UserMessage.DoesNotExist:
return None