From 79f8e2a6a3fddb9e1712c19ac0d6a7e6b51114c5 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 8 Nov 2012 14:38:17 -0500 Subject: [PATCH] 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) --- zephyr/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zephyr/views.py b/zephyr/views.py index 30d47f66a7..d5ac4a48b4 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -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):