'Called when we initially fill out user_directory one room at a time'

@defer.inlineCallbacks
def _handle_intial_room(self, room_id):

    is_in_room = (yield self.store.is_host_joined(room_id, self.server_name))
    if (not is_in_room):
        return
    is_public = (yield self.store.is_room_world_readable_or_publicly_joinable(room_id))
    users_with_profile = (yield self.state.get_current_user_in_room(room_id))
    user_ids = set(users_with_profile)
    unhandled_users = (user_ids - self.initially_handled_users)
    (yield self.store.add_profiles_to_user_dir(room_id, {user_id: users_with_profile[user_id] for user_id in unhandled_users}))
    self.initially_handled_users |= unhandled_users
    if is_public:
        (yield self.store.add_users_to_public_room(room_id, user_ids=(user_ids - self.initially_handled_users_in_public)))
        self.initially_handled_users_in_public |= user_ids
    to_insert = set()
    to_update = set()
    count = 0
    for user_id in user_ids:
        if ((count % self.INITIAL_SLEEP_COUNT) == 0):
            (yield sleep((self.INITIAL_SLEEP_MS / 1000.0)))
        if (not self.is_mine_id(user_id)):
            count += 1
            continue
        if self.store.get_if_app_services_interested_in_user(user_id):
            count += 1
            continue
        for other_user_id in user_ids:
            if (user_id == other_user_id):
                continue
            if ((count % self.INITIAL_SLEEP_COUNT) == 0):
                (yield sleep((self.INITIAL_SLEEP_MS / 1000.0)))
            count += 1
            user_set = (user_id, other_user_id)
            if (user_set in self.initially_handled_users_share_private_room):
                continue
            if (user_set in self.initially_handled_users_share):
                if is_public:
                    continue
                to_update.add(user_set)
            else:
                to_insert.add(user_set)
            if is_public:
                self.initially_handled_users_share.add(user_set)
            else:
                self.initially_handled_users_share_private_room.add(user_set)
            if (len(to_insert) > self.INITIAL_BATCH_SIZE):
                (yield self.store.add_users_who_share_room(room_id, (not is_public), to_insert))
                to_insert.clear()
            if (len(to_update) > self.INITIAL_BATCH_SIZE):
                (yield self.store.update_users_who_share_room(room_id, (not is_public), to_update))
                to_update.clear()
    if to_insert:
        (yield self.store.add_users_who_share_room(room_id, (not is_public), to_insert))
        to_insert.clear()
    if to_update:
        (yield self.store.update_users_who_share_room(room_id, (not is_public), to_update))
        to_update.clear()
