From a2747517a31615fe52812c236f48f3258efb1fc4 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 29 Oct 2017 08:50:20 -0700 Subject: [PATCH] Extract StreamTopicTarget.get_active_subscriptions(). Note that this code leads to a slightly different query, because we join to one row in the small Recipient table to match stream_id to recipient.type_id. --- zerver/lib/actions.py | 5 +---- zerver/lib/stream_topic.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index d09f304884..205eecf737 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -830,10 +830,7 @@ def get_recipient_info(recipient, sender_id, stream_topic, possibly_mentioned_us assert(len(message_to_user_ids) in [1, 2]) elif recipient.type == Recipient.STREAM: - subscription_rows = Subscription.objects.filter( - recipient=recipient, - active=True, - ).values( + subscription_rows = stream_topic.get_active_subscriptions().values( 'user_profile_id', 'push_notifications', 'in_home_view', diff --git a/zerver/lib/stream_topic.py b/zerver/lib/stream_topic.py index a276368fa6..d9bc9b25e9 100644 --- a/zerver/lib/stream_topic.py +++ b/zerver/lib/stream_topic.py @@ -1,6 +1,13 @@ from typing import (Dict, List, Text, Set) +from django.db.models.query import QuerySet -from zerver.models import MutedTopic +from zerver.lib.stream_subscription import ( + get_active_subscriptions_for_stream_id, +) + +from zerver.models import ( + MutedTopic, +) class StreamTopicTarget(object): ''' @@ -26,3 +33,7 @@ class StreamTopicTarget(object): row['user_profile_id'] for row in query } + + def get_active_subscriptions(self): + # type: () -> QuerySet + return get_active_subscriptions_for_stream_id(self.stream_id)