get_public_streams: Return only streams someone is subscribed to.

This makes subscribing to zephyr classes for the zephyr class
mirroring bot a lot faster, since we don't need to subscribe to the
third of our streams on which no users will actually receive messages.

(imported from commit 029b7fb260b480db5599e3c9f9effc502f6d8b59)
This commit is contained in:
Tim Abbott 2012-11-08 14:38:17 -05:00
parent 70a8e51351
commit 79f8e2a6a3
1 changed files with 6 additions and 1 deletions

View File

@ -699,8 +699,13 @@ def notify_pointer_update(request):
@authenticated_api_view
def api_get_public_streams(request, user_profile):
# Only get streams someone is currently subscribed to
subs_filter = Subscription.objects.filter(active=True).values('recipient_id')
stream_ids = Recipient.objects.filter(
type=Recipient.STREAM, id__in=subs_filter).values('type_id')
streams = sorted(stream.name for stream in
Stream.objects.filter(realm=user_profile.realm))
Stream.objects.filter(id__in = stream_ids,
realm=user_profile.realm))
return json_success({"streams": streams})
def gather_subscriptions(user_profile):