def iter_stock_transactions(self, form_id): xform = FormAccessorCouch.get_form(form_id) assert xform.domain == _diff_state.domain, xform for report in get_all_stock_report_helpers_from_form(xform): for tx in report.transactions: yield report.report_type, tx if tx.action == TRANSACTION_TYPE_STOCKONHAND: yield report.report_type, tx
def references_case(form_id): try: form = FormAccessorCouch.get_form(form_id) except XFormNotFound: return True # assume case is referenced if form not found try: return case_id in get_case_ids_from_form(form) except MissingFormXml: return True # assume case is referenced if form XML is missing
def diff_form_state(form_id, *, in_couch=False): in_couch = in_couch or FormAccessorCouch.form_exists(form_id) in_sql = FormAccessorSQL.form_exists(form_id) couch_miss = "missing" if not in_couch and get_blob_db().metadb.get_for_parent(form_id): couch_miss = MISSING_BLOB_PRESENT old = {"form_state": FORM_PRESENT if in_couch else couch_miss} new = {"form_state": FORM_PRESENT if in_sql else "missing"} return old, new
def diff_form_state(form_id, *, in_couch=False): in_couch = in_couch or FormAccessorCouch.form_exists(form_id) in_sql = FormAccessorSQL.form_exists(form_id) couch_miss = "missing" if not in_couch and get_blob_db().metadb.get_for_parent(form_id): couch_miss = "missing, blob present" old = {"form_state": "present" if in_couch else couch_miss} new = {"form_state": "present" if in_sql else "missing"} return old, new
def _rebuild_queues(self, pool): prev_ids = self.queues.get_ids_from_run_timestamp() for chunked_ids in chunked(prev_ids, 100): chunk = list([_id for _id in chunked_ids if _id]) for form in FormAccessorCouch.get_forms(chunk): self._try_to_process_form(form, pool) self._try_to_process_queues(pool)
def _rebuild_queues(self, pool): prev_ids = self.queues.get_ids_from_run_timestamp() for chunked_ids in chunked(prev_ids, 100): chunk = list([_id for _id in chunked_ids if _id]) for form in FormAccessorCouch.get_forms(chunk): self._try_to_process_form(form, pool) self._try_to_process_queues(pool)
def _get_form(form_id): from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL from corehq.form_processor.backends.couch.dbaccessors import FormAccessorCouch try: return FormAccessorSQL.get_form(form_id) except XFormNotFound: pass try: return FormAccessorCouch.get_form(form_id) except ResourceNotFound: pass return None
def _get_form(form_id): from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL from corehq.form_processor.backends.couch.dbaccessors import FormAccessorCouch try: return FormAccessorSQL.get_form(form_id) except XFormNotFound: pass try: return FormAccessorCouch.get_form(form_id) except ResourceNotFound: pass return None
def _archive_form_data(args_json): def iter_forms_and_cases(): couch_form = FormAccessorCouch.get_form(form.form_id) # null form_id -> do not increment form counts in case diff queue yield None, get_case_ids(couch_form) args = list(args_json) try: args[0] = form = FormAccessorSQL.get_form(args_json[0]) except XFormNotFound: couch_form = FormAccessorCouch.get_form(args_json[0]) if couch_form.doc_type != "XFormInstance": # form has not been migrated yet; will be copied as "unprocessed form" raise IgnoreSystemAction # edge case: form was archived when migration started, then unarchived # during migration -> should be migrated as unarchived form raise return form.domain, args, iter_forms_and_cases
def _rebuild_queues(self, form_ids): for chunk in chunked(form_ids, 100, list): for form in FormAccessorCouch.get_forms(chunk): self._try_to_process_form(form)
def get_form(form_id): try: return FormAccessorSQL.get_form(form_id) except XFormNotFound: pass return FormAccessorCouch.get_form(form_id)
def iter_forms_and_cases(): couch_form = FormAccessorCouch.get_form(form.form_id) # null form_id -> do not increment form counts in case diff queue yield None, get_case_ids(couch_form)
def get_couch_forms(form_ids): return FormAccessorCouch.get_forms(form_ids)
def get_form_related(form_ids): return { form.form_id: (form.user_id, form.received_on) for form in FormAccessorCouch.get_forms(form_ids) }
def couch_form_exists(form_id): return FormAccessorCouch.form_exists(form_id)