(timing_context, restore_state, response, async_task=None)
Get case sync restore response

    This function makes no changes to external state other than updating
    the `restore_state.current_sync_log` and progress of `async_task`.
    Extends `response` with restore elements.
Get case sync restore response
Get case sync restore response
def do_livequery(timing_context, restore_state, response, async_task=None):
    """Get case sync restore response

    This function makes no changes to external state other than updating
    the `restore_state.current_sync_log` and progress of `async_task`.
    Extends `response` with restore elements.
    """

    debug = logging.getLogger(__name__).debug
    accessor = CaseAccessors(restore_state.domain)
    owner_ids = list(restore_state.owner_ids)

    debug("sync %s for %r", restore_state.current_sync_log._id, owner_ids)
    with timing_context("livequery"):
        with timing_context("get_case_ids_by_owners"):
            owned_ids = accessor.get_case_ids_by_owners(owner_ids, closed=False)
            debug("owned: %r", owned_ids)

        live_ids, indices = get_live_case_ids_and_indices(restore_state.domain, owned_ids, timing_context)

        if restore_state.last_sync_log:
            with timing_context("discard_already_synced_cases"):
                debug('last sync: %s', restore_state.last_sync_log._id)
                sync_ids = discard_already_synced_cases(
                    live_ids, restore_state, accessor)
        else:
            sync_ids = live_ids
        restore_state.current_sync_log.case_ids_on_phone = live_ids

        with timing_context("compile_response(%s cases)" % len(sync_ids)):
            iaccessor = PrefetchIndexCaseAccessor(accessor, indices)
            metrics_histogram(
                'commcare.restore.case_load',
                len(sync_ids),
                'cases',
                RESTORE_CASE_LOAD_BUCKETS,
                tags={
                    'domain': accessor.domain,
                    'restore_type': 'incremental' if restore_state.last_sync_log else 'fresh'
                }
            )
            metrics_counter('commcare.restore.case_load.count', len(sync_ids), {'domain': accessor.domain})
            compile_response(
                timing_context,
                restore_state,
                response,
                batch_cases(iaccessor, sync_ids),
                init_progress(async_task, len(sync_ids)),
            )
def do_livequery ( timing_context , restore_state , response , async_task = None ) : debug = logging . getLogger ( __name__ ) . debug accessor = CaseAccessors ( restore_state . domain ) owner_ids = list ( restore_state . owner_ids ) debug ( "sync %s for %r" , restore_state . current_sync_log . _id , owner_ids ) with timing_context ( "livequery" ) : with timing_context ( "get_case_ids_by_owners" ) : owned_ids = accessor . get_case_ids_by_owners ( owner_ids , closed = False ) debug ( "owned: %r" , owned_ids ) live_ids , indices = get_live_case_ids_and_indices ( restore_state . domain , owned_ids , timing_context ) if restore_state . last_sync_log : with timing_context ( "discard_already_synced_cases" ) : debug ( 'last sync: %s' , restore_state . last_sync_log . _id ) sync_ids = discard_already_synced_cases ( live_ids , restore_state , accessor ) else : sync_ids = live_ids restore_state . current_sync_log . case_ids_on_phone = live_ids with timing_context ( "compile_response(%s cases)" % len ( sync_ids ) ) : iaccessor = PrefetchIndexCaseAccessor ( accessor , indices ) metrics_histogram ( 'commcare.restore.case_load' , len ( sync_ids ) , 'cases' , RESTORE_CASE_LOAD_BUCKETS , tags = { 'domain' : accessor . domain , 'restore_type' : 'incremental' if restore_state . last_sync_log else 'fresh' } ) metrics_counter ( 'commcare.restore.case_load.count' , len ( sync_ids ) , { 'domain' : accessor . domain } ) compile_response ( timing_context , restore_state , response , batch_cases ( iaccessor , sync_ids ) , init_progress ( async_task , len ( sync_ids ) ) , )