(case, transactions, updated_xforms=None)
Fetches the forms for a list of transactions, caching them onto each transaction

        :param transactions: list of ``CaseTransaction`` objects:
        :param updated_xforms: list of forms that have been changed.
Fetches the forms for a list of transactions, caching them onto each transaction
Fetches the forms for a list of transactions caching them onto each transaction
def fetch_case_transaction_forms(case, transactions, updated_xforms=None):
        """
        Fetches the forms for a list of transactions, caching them onto each transaction

        :param transactions: list of ``CaseTransaction`` objects:
        :param updated_xforms: list of forms that have been changed.
        """

        form_ids = {tx.form_id for tx in transactions if tx.form_id}
        updated_xforms_map = {
            xform.form_id: xform for xform in updated_xforms if not xform.is_deprecated
        } if updated_xforms else {}

        updated_xform_ids = set(updated_xforms_map)
        form_ids_to_fetch = list(form_ids - updated_xform_ids)
        form_load_counter("rebuild_case", case.domain)(len(form_ids_to_fetch))
        xform_map = {
            form.form_id: form
            for form in FormAccessorSQL.get_forms_with_attachments_meta(form_ids_to_fetch)
        }

        forms_missing_transactions = list(updated_xform_ids - form_ids)
        for form_id in forms_missing_transactions:
            # Add in any transactions that aren't already present
            form = updated_xforms_map[form_id]
            case_updates = [update for update in get_case_updates(form) if update.id == case.case_id]
            types = [
                CaseTransaction.type_from_action_type_slug(a.action_type_slug)
                for case_update in case_updates
                for a in case_update.actions
            ]
            modified_on = case_updates[0].guess_modified_on()
            new_transaction = CaseTransaction.form_transaction(case, form, modified_on, types)
            transactions.append(new_transaction)

        def get_form(form_id):
            if form_id in updated_xforms_map:
                return updated_xforms_map[form_id]

            try:
                return xform_map[form_id]
            except KeyError:
                raise XFormNotFound(form_id)

        for case_transaction in transactions:
            if case_transaction.form_id:
                try:
                    case_transaction.cached_form = get_form(case_transaction.form_id)
                except XFormNotFound:
                    logging.error('Form not found during rebuild: %s', case_transaction.form_id)
def fetch_case_transaction_forms ( case , transactions , updated_xforms = None ) : form_ids = { tx . form_id for tx in transactions if tx . form_id } updated_xforms_map = { xform . form_id : xform for xform in updated_xforms if not xform . is_deprecated } if updated_xforms else { } updated_xform_ids = set ( updated_xforms_map ) form_ids_to_fetch = list ( form_ids - updated_xform_ids ) form_load_counter ( "rebuild_case" , case . domain ) ( len ( form_ids_to_fetch ) ) xform_map = { form . form_id : form for form in FormAccessorSQL . get_forms_with_attachments_meta ( form_ids_to_fetch ) } forms_missing_transactions = list ( updated_xform_ids - form_ids ) for form_id in forms_missing_transactions : # Add in any transactions that aren't already present form = updated_xforms_map [ form_id ] case_updates = [ update for update in get_case_updates ( form ) if update . id == case . case_id ] types = [ CaseTransaction . type_from_action_type_slug ( a . action_type_slug ) for case_update in case_updates for a in case_update . actions ] modified_on = case_updates [ 0 ] . guess_modified_on ( ) new_transaction = CaseTransaction . form_transaction ( case , form , modified_on , types ) transactions . append ( new_transaction ) def get_form ( form_id ) : if form_id in updated_xforms_map : return updated_xforms_map [ form_id ] try : return xform_map [ form_id ] except KeyError : raise XFormNotFound ( form_id ) for case_transaction in transactions : if case_transaction . form_id : try : case_transaction . cached_form = get_form ( case_transaction . form_id ) except XFormNotFound : logging . error ( 'Form not found during rebuild: %s' , case_transaction . form_id )