mirror of https://github.com/zulip/zulip.git
refactor: Streamline subscribed_to_stream().
The prior code uses an awkward idiom that pre-dates the `exists()` function, and it had an unreachable line of code. The new version should be faster, since we don't create a throwaway heavy Django object or send needless data over the wire.
This commit is contained in:
parent
c41377aaab
commit
040dafbfc5
|
@ -3693,15 +3693,11 @@ def do_update_message_flags(user_profile: UserProfile,
|
|||
return count
|
||||
|
||||
def subscribed_to_stream(user_profile: UserProfile, stream_id: int) -> bool:
|
||||
try:
|
||||
if Subscription.objects.get(user_profile=user_profile,
|
||||
return Subscription.objects.filter(
|
||||
user_profile=user_profile,
|
||||
active=True,
|
||||
recipient__type=Recipient.STREAM,
|
||||
recipient__type_id=stream_id):
|
||||
return True
|
||||
return False
|
||||
except Subscription.DoesNotExist:
|
||||
return False
|
||||
recipient__type_id=stream_id).exists()
|
||||
|
||||
def truncate_content(content: str, max_length: int, truncation_message: str) -> str:
|
||||
if len(content) > max_length:
|
||||
|
|
Loading…
Reference in New Issue