def get_owned(self, user_id):
        try:
            user = CouchUser.get_by_user_id(user_id, self.domain)
        except KeyError:
            user = None
        try:
            owner_ids = user.get_owner_ids()
        except __HOLE__:
            owner_ids = [user_id]

        closed = {
            CASE_STATUS_OPEN: False,
            CASE_STATUS_CLOSED: True,
            CASE_STATUS_ALL: None,
        }[self.status]

        ids = get_case_ids_in_domain_by_owner(
            self.domain, owner_id__in=owner_ids, closed=closed)

        return self._case_results(ids)


# todo: Make these api functions use generators for streaming
# so that a limit call won't fetch more docs than it needs to
# This could be achieved with something like CommCareCase.paging_view that
# returns a generator but internally batches couch requests
# potentially doubling the batch-size each time in case it really is a lot of data
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/cloudcare/api.py/CaseAPIHelper.get_owned