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.
This commit is contained in:
Steve Howell
2017-10-29 08:50:20 -07:00
committed by Tim Abbott
parent 8e0b417bd9
commit a2747517a3
2 changed files with 13 additions and 5 deletions

View File

@@ -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',

View File

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