'gather_subscriptions returns correct results with only 3 queries'

@slow('common_subscribe_to_streams    is    slow')
def test_gather_subscriptions_mit(self):

    mit_user_profile = self.mit_user('starnine')
    email = mit_user_profile.email
    users_to_subscribe = [email, self.mit_email('espuser')]
    for email in users_to_subscribe:
        self.subscribe_to_stream(email, 'mit_stream')
    ret = self.common_subscribe_to_streams(email, ['mit_invite_only'], dict(principals=ujson.dumps(users_to_subscribe)), invite_only=True)
    self.assert_json_success(ret)
    with queries_captured() as queries:
        subscriptions = gather_subscriptions(mit_user_profile)
    self.assertTrue((len(subscriptions[0]) >= 2))
    for sub in subscriptions[0]:
        if (not sub['name'].startswith('mit_')):
            raise AssertionError('Unexpected    stream!')
        if (sub['name'] == 'mit_invite_only'):
            self.assertTrue((len(sub['subscribers']) == len(users_to_subscribe)))
        else:
            self.assertTrue((len(sub['subscribers']) == 0))
    self.assert_length(queries, 4)
