Skip to content

Commit

Permalink
Merge pull request #34718 from dimagi/bmb/deet/case-prop-schema-optim…
Browse files Browse the repository at this point in the history
…ize-simple

Improve loading time of Clean Case Data panel
  • Loading branch information
biyeun authored Aug 30, 2024
2 parents 772c987 + 5a8246e commit a50d167
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
38 changes: 11 additions & 27 deletions corehq/apps/export/models/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@ def generate_schema_from_builds(
only_process_current_builds=False,
task=None,
for_new_export_instance=False,
is_identifier_case_type=False,
):
"""
Builds a schema from Application builds for a given identifier
Expand All @@ -1787,6 +1788,7 @@ def generate_schema_from_builds(
processed.
:param task: A celery task to update the progress of the build
:param for_new_export_instance: Flag to be set if generating schema for a new export instance
:param is_identifier_case_type: boolean, if True, some optimizations are applied specific to case type
:returns: Returns a ExportDataSchema instance
"""

Expand All @@ -1809,7 +1811,8 @@ def generate_schema_from_builds(
)
app_build_ids.extend(app_ids_for_domain)
current_schema = cls._process_apps_for_export(domain, current_schema, identifier, app_build_ids, task,
for_new_export_instance=for_new_export_instance)
for_new_export_instance=for_new_export_instance,
is_identifier_case_type=is_identifier_case_type)

inferred_schema = cls._get_inferred_schema(domain, app_id, identifier)
if inferred_schema:
Expand Down Expand Up @@ -1955,7 +1958,7 @@ def _save_export_schema(current_schema, original_id, original_rev):

@classmethod
def _process_apps_for_export(cls, domain, schema, identifier, app_build_ids, task,
for_new_export_instance=False):
for_new_export_instance=False, is_identifier_case_type=False):
apps_processed = 0
for app_doc in iter_docs(Application.get_db(), app_build_ids, chunksize=10):
doc_type = app_doc.get('doc_type', '')
Expand All @@ -1974,6 +1977,9 @@ def _process_apps_for_export(cls, domain, schema, identifier, app_build_ids, tas
)
continue

if is_identifier_case_type and not app.case_type_exists(identifier):
continue

try:
schema = cls._process_app_build(
schema,
Expand Down Expand Up @@ -2313,18 +2319,6 @@ def _get_stock_items_from_question(question, app_id, app_version, repeats):

return items

@classmethod
def _process_apps_for_export(cls, domain, schema, identifier, app_build_ids, task,
for_new_export_instance=False):
return super(FormExportDataSchema, cls)._process_apps_for_export(
domain,
schema,
identifier,
app_build_ids,
task,
for_new_export_instance=for_new_export_instance
)


class CaseExportDataSchema(ExportDataSchema):

Expand Down Expand Up @@ -2544,7 +2538,7 @@ def _add_to_group_schema(group_schema, path_start, prop, app_id, app_version):

@classmethod
def _process_apps_for_export(cls, domain, schema, identifier, app_build_ids, task,
for_new_export_instance=False):
for_new_export_instance=False, is_identifier_case_type=False):
if identifier == ALL_CASE_TYPE_EXPORT:
return cls._process_apps_for_bulk_export(domain, schema, app_build_ids, task)
else:
Expand All @@ -2554,7 +2548,8 @@ def _process_apps_for_export(cls, domain, schema, identifier, app_build_ids, tas
identifier,
app_build_ids,
task,
for_new_export_instance=for_new_export_instance
for_new_export_instance=for_new_export_instance,
is_identifier_case_type=is_identifier_case_type
)

@classmethod
Expand Down Expand Up @@ -2623,17 +2618,6 @@ def schema_version(cls):
def get_latest_export_schema(domain, include_metadata, identifier=None):
return SMSExportDataSchema(domain=domain, include_metadata=include_metadata)

def _process_apps_for_export(cls, domain, schema, identifier, app_build_ids, task,
for_new_export_instance=False):
return super(SMSExportDataSchema, cls)._process_apps_for_export(
domain,
schema,
identifier,
app_build_ids,
task,
for_new_export_instance=for_new_export_instance
)


def _string_path_to_list(path):
return path if path is None else path[1:].split('/')
Expand Down
3 changes: 2 additions & 1 deletion corehq/apps/reports/standard/cases/case_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ def case_property_names(request, domain, case_id):
# We need to look at the export schema in order to remove any case properties that
# have been deleted from the app. When the data dictionary is fully public, we can use that
# so that users may deprecate those properties manually
export_schema = CaseExportDataSchema.generate_schema_from_builds(domain, None, case.type)
export_schema = CaseExportDataSchema.generate_schema_from_builds(domain, None, case.type,
is_identifier_case_type=True)
property_schema = export_schema.group_schemas[0]
last_app_ids = get_latest_app_ids_and_versions(domain)
all_property_names = {
Expand Down

0 comments on commit a50d167

Please sign in to comment.