mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
performance: Avoid Recipient lookup.
We don't have to go to the database to get the Recipient
fields for `user_profile.recipient`.
See also 85ed6f332a from a little
over a year ago--it's very similar.
This commit is contained in:
@@ -2647,7 +2647,11 @@ def get_recipient_from_user_profiles(
|
|||||||
assert recipient_profiles_map
|
assert recipient_profiles_map
|
||||||
if len(recipient_profiles_map) == 1:
|
if len(recipient_profiles_map) == 1:
|
||||||
[user_profile] = recipient_profiles_map.values()
|
[user_profile] = recipient_profiles_map.values()
|
||||||
return user_profile.recipient
|
return Recipient(
|
||||||
|
id=user_profile.recipient_id,
|
||||||
|
type=Recipient.PERSONAL,
|
||||||
|
type_id=user_profile.id,
|
||||||
|
)
|
||||||
|
|
||||||
# Otherwise, we need a huddle. Make sure the sender is included in huddle messages
|
# Otherwise, we need a huddle. Make sure the sender is included in huddle messages
|
||||||
recipient_profiles_map[sender.id] = sender
|
recipient_profiles_map[sender.id] = sender
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ class TestQueryCounts(ZulipTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# The assert_length helper is another useful extra from ZulipTestCase.
|
# The assert_length helper is another useful extra from ZulipTestCase.
|
||||||
self.assert_length(queries, 16)
|
self.assert_length(queries, 15)
|
||||||
|
|
||||||
|
|
||||||
class TestDevelopmentEmailsLog(ZulipTestCase):
|
class TestDevelopmentEmailsLog(ZulipTestCase):
|
||||||
|
|||||||
@@ -799,7 +799,7 @@ class QueryCountTest(ZulipTestCase):
|
|||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assert_length(queries, 85)
|
self.assert_length(queries, 84)
|
||||||
self.assert_length(cache_tries, 27)
|
self.assert_length(cache_tries, 27)
|
||||||
|
|
||||||
peer_add_events = [event for event in events if event["event"].get("op") == "peer_add"]
|
peer_add_events = [event for event in events if event["event"].get("op") == "peer_add"]
|
||||||
|
|||||||
Reference in New Issue
Block a user