Optimize get_occupied_streams

In a test run with a hand-constructed query, this sped up the query time from
280ms to 50ms.

(imported from commit 8cbe199ca50a487491d13d6d6ef940ea668c1038)
This commit is contained in:
Zev Benjamin
2014-03-06 17:34:44 -05:00
committed by Steve Howell
parent 2090d6ee27
commit eda05d23bf

View File

@@ -2732,7 +2732,8 @@ def realm_aliases(realm):
def get_occupied_streams(realm):
""" Get streams with subscribers """
subs_filter = Subscription.objects.filter(active=True).values('recipient_id')
subs_filter = Subscription.objects.filter(active=True, user_profile__realm=realm,
user_profile__is_active=True).values('recipient_id')
stream_ids = Recipient.objects.filter(
type=Recipient.STREAM, id__in=subs_filter).values('type_id')