users: Eliminate some unnecessary get_personal_recipient calls.

This commit is contained in:
Mateusz Mandera 2019-12-05 23:35:33 +01:00 committed by Tim Abbott
parent 467833a974
commit 1c5461663f
2 changed files with 5 additions and 5 deletions

View File

@ -23,7 +23,7 @@ from zerver.lib.send_email import FromAddress
from zerver.lib.rate_limiter import RateLimitedObject, rate_limit_entity
from zerver.lib.exceptions import RateLimited
from zerver.models import Stream, Recipient, \
get_user_profile_by_id, get_display_recipient, get_personal_recipient, \
get_user_profile_by_id, get_display_recipient, \
Message, Realm, UserProfile, get_system_bot, get_user, get_stream_by_id_in_realm
from zproject.backends import is_user_active
@ -118,7 +118,7 @@ def create_missed_message_address(user_profile: UserProfile, message: Message) -
if message.recipient.type == Recipient.PERSONAL:
# We need to reply to the sender so look up their personal recipient_id
recipient_id = get_personal_recipient(message.sender_id).id
recipient_id = message.sender.recipient_id
else:
recipient_id = message.recipient_id

View File

@ -51,7 +51,7 @@ from zerver.lib.validator import \
check_string_or_int_list, check_string_or_int
from zerver.lib.zephyr import compute_mit_user_fullname
from zerver.models import Message, UserProfile, Stream, Subscription, Client,\
Realm, RealmDomain, Recipient, UserMessage, bulk_get_recipients, get_personal_recipient, \
Realm, RealmDomain, Recipient, UserMessage, bulk_get_recipients, \
email_to_domain, get_realm, get_active_streams, get_user_including_cross_realm, \
get_user_by_id_in_realm_including_cross_realm
@ -391,9 +391,9 @@ class NarrowBuilder:
# the thread (the sender), we need to do a somewhat
# complex query to get messages between these two users
# with either of them as the sender.
self_recipient = get_personal_recipient(self.user_profile.id)
self_recipient_id = self.user_profile.recipient_id
cond = or_(and_(column("sender_id") == other_participant.id,
column("recipient_id") == self_recipient.id),
column("recipient_id") == self_recipient_id),
and_(column("sender_id") == self.user_profile.id,
column("recipient_id") == recipient.id))
return query.where(maybe_negate(cond))