models: Remove get_huddle_recipient and use get_or_create_huddle.

This commit removes get_huddle_recipient function and we now use
get_or_create_huddle in get_recipient_from_user_profiles.

As a result of this change, we do not fetch the recipient from
Huddle object but instead get it using the "id" and "recipient_id"
fields available from Huddle object like we do for a personal
message. This change allows us to not fetch recipient object
using select_related when querying the Huddle object.
This commit is contained in:
Sahil Batra
2023-08-09 19:52:16 +05:30
committed by Tim Abbott
parent 2c28b49680
commit 91a58d026b
3 changed files with 17 additions and 26 deletions

View File

@@ -56,7 +56,7 @@ from zerver.models import (
UserMessage,
UserProfile,
flush_per_request_caches,
get_huddle_recipient,
get_or_create_huddle,
get_realm,
get_stream,
get_system_bot,
@@ -660,16 +660,14 @@ class MessagePOSTTest(ZulipTestCase):
msg = self.get_last_message()
self.assertEqual("Test message", msg.content)
self.assertEqual(
msg.recipient_id,
get_huddle_recipient(
{
self.example_user("hamlet").id,
self.example_user("othello").id,
self.example_user("cordelia").id,
}
).id,
huddle = get_or_create_huddle(
[
self.example_user("hamlet").id,
self.example_user("othello").id,
self.example_user("cordelia").id,
]
)
self.assertEqual(msg.recipient_id, huddle.recipient_id)
def test_personal_message_copying_self(self) -> None:
"""