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:
Steve Howell 2018-08-15 17:12:25 +00:00 committed by Tim Abbott
parent c41377aaab
commit 040dafbfc5
1 changed files with 5 additions and 9 deletions

View File

@ -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: