def get_contact_info(domain):
    # If the data has been cached, just retrieve it from there
    cache_key = 'sms-chat-contact-list-%s' % domain
    cache_expiration = 30 * 60
    try:
        client = cache_core.get_redis_client()
        cached_data = client.get(cache_key)
        if cached_data:
            return json.loads(cached_data)
    except:
        pass

    verified_number_ids = VerifiedNumber.by_domain(domain, ids_only=True)
    domain_obj = Domain.get_by_name(domain, strict=True)
    case_ids = []
    mobile_worker_ids = []
    data = []
    for doc in iter_docs(VerifiedNumber.get_db(), verified_number_ids):
        owner_id = doc['owner_id']
        if doc['owner_doc_type'] == 'CommCareCase':
            case_ids.append(owner_id)
            data.append([
                None,
                'case',
                doc['phone_number'],
                owner_id,
                doc['_id'],
            ])
        elif doc['owner_doc_type'] == 'CommCareUser':
            mobile_worker_ids.append(owner_id)
            data.append([
                None,
                'mobile_worker',
                doc['phone_number'],
                owner_id,
                doc['_id'],
            ])
    contact_data = get_case_contact_info(domain_obj, case_ids)
    contact_data.update(get_mobile_worker_contact_info(domain_obj, mobile_worker_ids))
    for row in data:
        contact_info = contact_data.get(row[3])
        row[0] = contact_info[0] if contact_info else _('(unknown)')

    # Save the data to the cache for faster lookup next time
    try:
        client.set(cache_key, json.dumps(data))
        client.expire(cache_key, cache_expiration)
    except:
        pass

    return data
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sms/views.py/get_contact_info/original